home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Science⁄Math / meschach / meschach0.shar < prev    next >
Encoding:
Text File  |  1994-06-07  |  393.1 KB  |  13,827 lines  |  [TEXT/ttxt]

  1. # to unbundle, sh this file (in an empty directory)
  2. echo dmacheps.c 1>&2
  3. sed >dmacheps.c <<'//GO.SYSIN DD dmacheps.c' 's/^-//'
  4. -
  5. -/**************************************************************************
  6. -**
  7. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  8. -**
  9. -**                 Meschach Library
  10. -** 
  11. -** This Meschach Library is provided "as is" without any express 
  12. -** or implied warranty of any kind with respect to this software. 
  13. -** In particular the authors shall not be liable for any direct, 
  14. -** indirect, special, incidental or consequential damages arising 
  15. -** in any way from use of the software.
  16. -** 
  17. -** Everyone is granted permission to copy, modify and redistribute this
  18. -** Meschach Library, provided:
  19. -**  1.  All copies contain this copyright notice.
  20. -**  2.  All modified copies shall carry a notice stating who
  21. -**      made the last modification and the date of such modification.
  22. -**  3.  No charge is made for this software or works derived from it.  
  23. -**      This clause shall not be construed as constraining other software
  24. -**      distributed on the same medium as this software, nor is a
  25. -**      distribution fee considered a charge.
  26. -**
  27. -***************************************************************************/
  28. -
  29. -
  30. -#include    <stdio.h>
  31. -
  32. -double    dclean(x)
  33. -double    x;
  34. -{
  35. -    static double    y;
  36. -    y = x;
  37. -    return y;    /* prevents optimisation */
  38. -}
  39. -
  40. -main()
  41. -{
  42. -    static double    deps, deps1, dtmp;
  43. -
  44. -    deps = 1.0;
  45. -    while ( dclean(1.0+deps) > 1.0 )
  46. -    deps = 0.5*deps;
  47. -
  48. -    printf("%g\n", 2.0*deps);
  49. -}
  50. //GO.SYSIN DD dmacheps.c
  51. echo extras.c 1>&2
  52. sed >extras.c <<'//GO.SYSIN DD extras.c' 's/^-//'
  53. -
  54. -/**************************************************************************
  55. -**
  56. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  57. -**
  58. -**                 Meschach Library
  59. -** 
  60. -** This Meschach Library is provided "as is" without any express 
  61. -** or implied warranty of any kind with respect to this software. 
  62. -** In particular the authors shall not be liable for any direct, 
  63. -** indirect, special, incidental or consequential damages arising 
  64. -** in any way from use of the software.
  65. -** 
  66. -** Everyone is granted permission to copy, modify and redistribute this
  67. -** Meschach Library, provided:
  68. -**  1.  All copies contain this copyright notice.
  69. -**  2.  All modified copies shall carry a notice stating who
  70. -**      made the last modification and the date of such modification.
  71. -**  3.  No charge is made for this software or works derived from it.  
  72. -**      This clause shall not be construed as constraining other software
  73. -**      distributed on the same medium as this software, nor is a
  74. -**      distribution fee considered a charge.
  75. -**
  76. -***************************************************************************/
  77. -
  78. -
  79. -/*
  80. -    Memory port routines: MEM_COPY and MEM_ZERO
  81. -*/
  82. -
  83. -/* For BSD 4.[23] environments: using bcopy() and bzero() */
  84. -
  85. -#include "machine.h"
  86. -
  87. -#ifndef MEM_COPY
  88. -void    MEM_COPY(from,to,len)
  89. -char    *from, *to;
  90. -int    len;
  91. -{
  92. -    int        i;
  93. -
  94. -    if ( from < to )
  95. -    {
  96. -    for ( i = 0; i < len; i++ )
  97. -        *to++ = *from++;
  98. -    }
  99. -    else
  100. -    {
  101. -    from += len;    to += len;
  102. -    for ( i = 0; i < len; i++ )
  103. -        *(--to) = *(--from);
  104. -    }
  105. -}
  106. -#endif
  107. -
  108. -#ifndef MEM_ZERO
  109. -void    MEM_ZERO(ptr,len)
  110. -char    *ptr;
  111. -int    len;
  112. -{
  113. -    int        i;
  114. -
  115. -    for ( i = 0; i < len; i++ )
  116. -    *(ptr++) = '\0';
  117. -}
  118. -#endif
  119. -
  120. -/*
  121. -    This file contains versions of something approximating the well-known
  122. -    BLAS routines in C, suitable for Meschach (hence the `m').
  123. -    These are "vanilla" implementations, at least with some consideration
  124. -    of the effects of caching and paging, and maybe some loop unrolling
  125. -    for register-rich machines
  126. -*/
  127. -
  128. -/*
  129. -    Organisation of matrices: it is assumed that matrices are represented
  130. -    by Real **'s. To keep flexibility, there is also an "initial
  131. -    column" parameter j0, so that the actual elements used are
  132. -        A[0][j0],   A[0][j0+1],   ..., A[0][j0+n-1]
  133. -        A[1][j0],   A[1][j0+1],   ..., A[1][j0+n-1]
  134. -           ..         ..          ...      ..
  135. -        A[m-1][j0], A[m-1][j0+1], ..., A[m-1][j0+n-1]
  136. -*/
  137. -
  138. -static char    rcsid[] = "$Id: extras.c,v 1.3 1994/01/13 05:45:36 des Exp $";
  139. -
  140. -#include    <math.h>
  141. -
  142. -#define    REGISTER_RICH    1
  143. -
  144. -/* mblar-1 routines */
  145. -
  146. -/* Mscale -- sets x <- alpha.x */
  147. -void    Mscale(len,alpha,x)
  148. -int    len;
  149. -double    alpha;
  150. -Real    *x;
  151. -{
  152. -    register int    i;
  153. -
  154. -    for ( i = 0; i < len; i++ )
  155. -    x[i] *= alpha;
  156. -}
  157. -
  158. -/* Mswap -- swaps x and y */
  159. -void    Mswap(len,x,y)
  160. -int    len;
  161. -Real    *x, *y;
  162. -{
  163. -    register int    i;
  164. -    register Real    tmp;
  165. -
  166. -    for ( i = 0; i < len; i++ )
  167. -    {
  168. -    tmp = x[i];
  169. -    x[i] = y[i];
  170. -    y[i] = tmp;
  171. -    }
  172. -}
  173. -
  174. -/* Mcopy -- copies x to y */
  175. -void    Mcopy(len,x,y)
  176. -int    len;
  177. -Real    *x, *y;
  178. -{
  179. -    register int    i;
  180. -
  181. -    for ( i = 0; i < len; i++ )
  182. -    y[i] = x[i];
  183. -}
  184. -
  185. -/* Maxpy -- y <- y + alpha.x */
  186. -void    Maxpy(len,alpha,x,y)
  187. -int    len;
  188. -double    alpha;
  189. -Real    *x, *y;
  190. -{
  191. -    register int    i, len4;
  192. -
  193. -    /****************************************
  194. -    for ( i = 0; i < len; i++ )
  195. -    y[i] += alpha*x[i];
  196. -    ****************************************/
  197. -
  198. -#ifdef REGISTER_RICH
  199. -    len4 = len / 4;
  200. -    len  = len % 4;
  201. -    for ( i = 0; i < len4; i++ )
  202. -    {
  203. -    y[4*i]   += alpha*x[4*i];
  204. -    y[4*i+1] += alpha*x[4*i+1];
  205. -    y[4*i+2] += alpha*x[4*i+2];
  206. -    y[4*i+3] += alpha*x[4*i+3];
  207. -    }
  208. -    x += 4*len4;    y += 4*len4;
  209. -#endif
  210. -    for ( i = 0; i < len; i++ )
  211. -    y[i] += alpha*x[i];
  212. -}
  213. -
  214. -/* Mdot -- returns x'.y */
  215. -double    Mdot(len,x,y)
  216. -int    len;
  217. -Real    *x, *y;
  218. -{
  219. -    register int    i, len4;
  220. -    register Real    sum;
  221. -
  222. -#ifndef REGISTER_RICH
  223. -    sum = 0.0;
  224. -#endif
  225. -
  226. -#ifdef REGISTER_RICH
  227. -    register Real    sum0, sum1, sum2, sum3;
  228. -    
  229. -    sum0 = sum1 = sum2 = sum3 = 0.0;
  230. -    
  231. -    len4 = len / 4;
  232. -    len  = len % 4;
  233. -    
  234. -    for ( i = 0; i < len4; i++ )
  235. -    {
  236. -    sum0 += x[4*i  ]*y[4*i  ];
  237. -    sum1 += x[4*i+1]*y[4*i+1];
  238. -    sum2 += x[4*i+2]*y[4*i+2];
  239. -    sum3 += x[4*i+3]*y[4*i+3];
  240. -    }
  241. -    sum = sum0 + sum1 + sum2 + sum3;
  242. -    x += 4*len4;    y += 4*len4;
  243. -#endif
  244. -
  245. -    for ( i = 0; i < len; i++ )
  246. -    sum += x[i]*y[i];
  247. -
  248. -    return sum;
  249. -}
  250. -
  251. -#ifndef ABS
  252. -#define    ABS(x)    ((x) >= 0 ? (x) : -(x))
  253. -#endif
  254. -
  255. -/* Mnorminf -- returns ||x||_inf */
  256. -double    Mnorminf(len,x)
  257. -int    len;
  258. -Real    *x;
  259. -{
  260. -    register int    i;
  261. -    register Real    tmp, max_val;
  262. -
  263. -    max_val = 0.0;
  264. -    for ( i = 0; i < len; i++ )
  265. -    {
  266. -    tmp = ABS(x[i]);
  267. -    if ( max_val < tmp )
  268. -        max_val = tmp;
  269. -    }
  270. -
  271. -    return max_val;
  272. -}
  273. -
  274. -/* Mnorm1 -- returns ||x||_1 */
  275. -double    Mnorm1(len,x)
  276. -int    len;
  277. -Real    *x;
  278. -{
  279. -    register int    i;
  280. -    register Real    sum;
  281. -
  282. -    sum = 0.0;
  283. -    for ( i = 0; i < len; i++ )
  284. -    sum += ABS(x[i]);
  285. -
  286. -    return sum;
  287. -}
  288. -
  289. -/* Mnorm2 -- returns ||x||_2 */
  290. -double    Mnorm2(len,x)
  291. -int    len;
  292. -Real    *x;
  293. -{
  294. -    register int    i;
  295. -    register Real    norm, invnorm, sum, tmp;
  296. -
  297. -    norm = Mnorminf(len,x);
  298. -    if ( norm == 0.0 )
  299. -    return 0.0;
  300. -    invnorm = 1.0/norm;
  301. -    sum = 0.0;
  302. -    for ( i = 0; i < len; i++ )
  303. -    {
  304. -    tmp = x[i]*invnorm;
  305. -    sum += tmp*tmp;
  306. -    }
  307. -
  308. -    return sum/invnorm;
  309. -}
  310. -
  311. -/* mblar-2 routines */
  312. -
  313. -/* Mmv -- y <- alpha.A.x + beta.y */
  314. -void    Mmv(m,n,alpha,A,j0,x,beta,y)
  315. -int    m, n, j0;
  316. -double    alpha, beta;
  317. -Real    **A, *x, *y;
  318. -{
  319. -    register int    i, j, m4, n4;
  320. -    register Real    sum0, sum1, sum2, sum3, tmp0, tmp1, tmp2, tmp3;
  321. -    register Real    *dp0, *dp1, *dp2, *dp3;
  322. -
  323. -    /****************************************
  324. -    for ( i = 0; i < m; i++ )
  325. -    y[i] += alpha*Mdot(n,&(A[i][j0]),x);
  326. -    ****************************************/
  327. -
  328. -    m4 = n4 = 0;
  329. -
  330. -#ifdef REGISTER_RICH
  331. -    m4 = m / 4;
  332. -    m  = m % 4;
  333. -    n4 = n / 4;
  334. -    n  = n % 4;
  335. -
  336. -    for ( i = 0; i < m4; i++ )
  337. -    {
  338. -    sum0 = sum1 = sum2 = sum3 = 0.0;
  339. -    dp0 = &(A[4*i  ][j0]);
  340. -    dp1 = &(A[4*i+1][j0]);
  341. -    dp2 = &(A[4*i+2][j0]);
  342. -    dp3 = &(A[4*i+3][j0]);
  343. -
  344. -    for ( j = 0; j < n4; j++ )
  345. -    {
  346. -        tmp0 = x[4*j  ];
  347. -        tmp1 = x[4*j+1];
  348. -        tmp2 = x[4*j+2];
  349. -        tmp3 = x[4*j+3];
  350. -        sum0 = sum0 + dp0[j]*tmp0 + dp0[j+1]*tmp1 +
  351. -        dp0[j+2]*tmp2 + dp0[j+3]*tmp3;
  352. -        sum1 = sum1 + dp1[j]*tmp0 + dp1[j+1]*tmp1 +
  353. -        dp1[j+2]*tmp2 + dp1[j+3]*tmp3;
  354. -        sum2 = sum2 + dp2[j]*tmp0 + dp2[j+1]*tmp1 +
  355. -        dp2[j+2]*tmp2 + dp2[j+3]*tmp3;
  356. -        sum3 = sum3 + dp3[j]*tmp0 + dp3[j+1]*tmp2 +
  357. -        dp3[j+2]*tmp2 + dp3[j+3]*tmp3;
  358. -    }
  359. -    for ( j = 0; j < n; j++ )
  360. -    {
  361. -        sum0 += dp0[4*n4+j]*x[4*n4+j];
  362. -        sum1 += dp1[4*n4+j]*x[4*n4+j];
  363. -        sum2 += dp2[4*n4+j]*x[4*n4+j];
  364. -        sum3 += dp3[4*n4+j]*x[4*n4+j];
  365. -    }
  366. -    y[4*i  ] = beta*y[4*i  ] + alpha*sum0;
  367. -    y[4*i+1] = beta*y[4*i+1] + alpha*sum1;
  368. -    y[4*i+2] = beta*y[4*i+2] + alpha*sum2;
  369. -    y[4*i+3] = beta*y[4*i+3] + alpha*sum3;
  370. -    }
  371. -#endif
  372. -
  373. -    for ( i = 0; i < m; i++ )
  374. -    y[4*m4+i] = beta*y[i] + alpha*Mdot(4*n4+n,&(A[4*m4+i][j0]),x);
  375. -}
  376. -
  377. -/* Mvm -- y <- alpha.A^T.x + beta.y */
  378. -void    Mvm(m,n,alpha,A,j0,x,beta,y)
  379. -int    m, n, j0;
  380. -double    alpha, beta;
  381. -Real    **A, *x, *y;
  382. -{
  383. -    register int    i, j, m4, n2;
  384. -    register Real    *Aref;
  385. -    register Real     tmp;
  386. -
  387. -#ifdef REGISTER_RICH
  388. -    register Real    *Aref0, *Aref1;
  389. -    register Real    tmp0, tmp1;
  390. -    register Real    yval0, yval1, yval2, yval3;
  391. -#endif
  392. -
  393. -    if ( beta != 1.0 )
  394. -    Mscale(m,beta,y);
  395. -    /****************************************
  396. -    for ( j = 0; j < n; j++ )
  397. -    Maxpy(m,alpha*x[j],&(A[j][j0]),y);
  398. -    ****************************************/
  399. -    m4 = n2 = 0;
  400. -
  401. -    m4 = m / 4;
  402. -    m  = m % 4;
  403. -#ifdef REGISTER_RICH
  404. -    n2 = n / 2;
  405. -    n  = n % 2;
  406. -
  407. -    for ( j = 0; j < n2; j++ )
  408. -    {
  409. -    tmp0 = alpha*x[2*j];
  410. -    tmp1 = alpha*x[2*j+1];
  411. -    Aref0 = &(A[2*j  ][j0]);
  412. -    Aref1 = &(A[2*j+1][j0]);
  413. -    for ( i = 0; i < m4; i++ )
  414. -    {
  415. -        yval0 = y[4*i  ] + tmp0*Aref0[4*i  ];
  416. -        yval1 = y[4*i+1] + tmp0*Aref0[4*i+1];
  417. -        yval2 = y[4*i+2] + tmp0*Aref0[4*i+2];
  418. -        yval3 = y[4*i+3] + tmp0*Aref0[4*i+3];
  419. -        y[4*i  ] = yval0 + tmp1*Aref1[4*i  ];
  420. -        y[4*i+1] = yval1 + tmp1*Aref1[4*i+1];
  421. -        y[4*i+2] = yval2 + tmp1*Aref1[4*i+2];
  422. -        y[4*i+3] = yval3 + tmp1*Aref1[4*i+3];
  423. -    }
  424. -    y += 4*m4;    Aref0 += 4*m4;    Aref1 += 4*m4;
  425. -    for ( i = 0; i < m; i++ )
  426. -        y[i] += tmp0*Aref0[i] + tmp1*Aref1[i];
  427. -    }
  428. -#endif
  429. -
  430. -    for ( j = 0; j < n; j++ )
  431. -    {
  432. -    tmp = alpha*x[2*n2+j];
  433. -    Aref = &(A[2*n2+j][j0]);
  434. -    for ( i = 0; i < m4; i++ )
  435. -    {
  436. -        y[4*i  ] += tmp*Aref[4*i  ];
  437. -        y[4*i+1] += tmp*Aref[4*i+1];
  438. -        y[4*i+2] += tmp*Aref[4*i+2];
  439. -        y[4*i+3] += tmp*Aref[4*i+3];
  440. -    }
  441. -    y += 4*m4;    Aref += 4*m4;
  442. -    for ( i = 0; i < m; i++ )
  443. -        y[i] += tmp*Aref[i];
  444. -    }
  445. -}
  446. -
  447. -/* Mupdate -- A <- A + alpha.x.y^T */
  448. -void    Mupdate(m,n,alpha,x,y,A,j0)
  449. -int    m, n, j0;
  450. -double    alpha;
  451. -Real    **A, *x, *y;
  452. -{
  453. -    register int    i, j, n4;
  454. -    register Real    *Aref;
  455. -    register Real     tmp;
  456. -
  457. -    /****************************************
  458. -    for ( i = 0; i < m; i++ )
  459. -    Maxpy(n,alpha*x[i],y,&(A[i][j0]));
  460. -    ****************************************/
  461. -
  462. -    n4 = n / 4;
  463. -    n  = n % 4;
  464. -    for ( i = 0; i < m; i++ )
  465. -    {
  466. -    tmp = alpha*x[i];
  467. -    Aref = &(A[i][j0]);
  468. -    for ( j = 0; j < n4; j++ )
  469. -    {
  470. -        Aref[4*j  ] += tmp*y[4*j  ];
  471. -        Aref[4*j+1] += tmp*y[4*j+1];
  472. -        Aref[4*j+2] += tmp*y[4*j+2];
  473. -        Aref[4*j+3] += tmp*y[4*j+3];
  474. -    }
  475. -    Aref += 4*n4;    y += 4*n4;
  476. -    for ( j = 0; j < n; j++ )
  477. -        Aref[j] += tmp*y[j];
  478. -    }
  479. -}
  480. -
  481. -/* mblar-3 routines */
  482. -
  483. -/* Mmm -- C <- C + alpha.A.B */
  484. -void    Mmm(m,n,p,alpha,A,Aj0,B,Bj0,C,Cj0)
  485. -int    m, n, p;    /* C is m x n */
  486. -double  alpha;
  487. -Real    **A, **B, **C;
  488. -int    Aj0, Bj0, Cj0;
  489. -{
  490. -    register int    i, j, k;
  491. -    /* register Real    tmp, sum; */
  492. -
  493. -    /****************************************
  494. -    for ( i = 0; i < m; i++ )
  495. -    for ( k = 0; k < p; k++ )
  496. -        Maxpy(n,alpha*A[i][Aj0+k],&(B[k][Bj0]),&(C[i][Cj0]));
  497. -    ****************************************/
  498. -    for ( i = 0; i < m; i++ )
  499. -    Mvm(p,n,alpha,&(A[i][Aj0]),B,Bj0,&(C[i][Cj0]));
  500. -}
  501. -
  502. -/* Mmtrm -- C <- C + alpha.A^T.B */
  503. -void    Mmtrm(m,n,p,alpha,A,Aj0,B,Bj0,C,Cj0)
  504. -int    m, n, p;    /* C is m x n */
  505. -double  alpha;
  506. -Real    **A, **B, **C;
  507. -int    Aj0, Bj0, Cj0;
  508. -{
  509. -    register int    i, j, k;
  510. -
  511. -    /****************************************
  512. -    for ( i = 0; i < m; i++ )
  513. -    for ( k = 0; k < p; k++ )
  514. -        Maxpy(n,alpha*A[k][Aj0+i],&(B[k][Bj0]),&(C[i][Cj0]));
  515. -    ****************************************/
  516. -    for ( k = 0; k < p; k++ )
  517. -    Mupdate(m,n,alpha,&(A[k][Aj0]),&(B[k][Bj0]),C,Cj0);
  518. -}
  519. -
  520. -/* Mmmtr -- C <- C + alpha.A.B^T */
  521. -void    Mmmtr(m,n,p,alpha,A,Aj0,B,Bj0,C,Cj0)
  522. -int    m, n, p;    /* C is m x n */
  523. -double  alpha;
  524. -Real    **A, **B, **C;
  525. -int    Aj0, Bj0, Cj0;
  526. -{
  527. -    register int    i, j, k;
  528. -
  529. -    /****************************************
  530. -    for ( i = 0; i < m; i++ )
  531. -    for ( j = 0; j < n; j++ )
  532. -        C[i][Cj0+j] += alpha*Mdot(p,&(A[i][Aj0]),&(B[j][Bj0]));
  533. -    ****************************************/
  534. -    for ( i = 0; i < m; i++ )
  535. -    Mmv(n,p,alpha,&(A[i][Aj0]),B,Bj0,&(C[i][Cj0]));
  536. -}
  537. -
  538. -/* Mmtrmtr -- C <- C + alpha.A^T.B^T */
  539. -void    Mmtrmtr(m,n,p,alpha,A,Aj0,B,Bj0,C,Cj0)
  540. -int    m, n, p;    /* C is m x n */
  541. -double  alpha;
  542. -Real    **A, **B, **C;
  543. -int    Aj0, Bj0, Cj0;
  544. -{
  545. -    register int    i, j, k;
  546. -
  547. -    for ( i = 0; i < m; i++ )
  548. -    for ( j = 0; j < n; j++ )
  549. -        for ( k = 0; k < p; k++ )
  550. -        C[i][Cj0+j] += A[i][Aj0+k]*B[k][Bj0+j];
  551. -}
  552. -
  553. //GO.SYSIN DD extras.c
  554. echo fmacheps.c 1>&2
  555. sed >fmacheps.c <<'//GO.SYSIN DD fmacheps.c' 's/^-//'
  556. -
  557. -/**************************************************************************
  558. -**
  559. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  560. -**
  561. -**                 Meschach Library
  562. -** 
  563. -** This Meschach Library is provided "as is" without any express 
  564. -** or implied warranty of any kind with respect to this software. 
  565. -** In particular the authors shall not be liable for any direct, 
  566. -** indirect, special, incidental or consequential damages arising 
  567. -** in any way from use of the software.
  568. -** 
  569. -** Everyone is granted permission to copy, modify and redistribute this
  570. -** Meschach Library, provided:
  571. -**  1.  All copies contain this copyright notice.
  572. -**  2.  All modified copies shall carry a notice stating who
  573. -**      made the last modification and the date of such modification.
  574. -**  3.  No charge is made for this software or works derived from it.  
  575. -**      This clause shall not be construed as constraining other software
  576. -**      distributed on the same medium as this software, nor is a
  577. -**      distribution fee considered a charge.
  578. -**
  579. -***************************************************************************/
  580. -
  581. -
  582. -#include    <stdio.h>
  583. -
  584. -double    fclean(x)
  585. -double    x;
  586. -{
  587. -    static float    y;
  588. -    y = x;
  589. -    return y;    /* prevents optimisation */
  590. -}
  591. -
  592. -main()
  593. -{
  594. -    static float    feps, feps1, ftmp;
  595. -
  596. -    feps = 1.0;
  597. -    while ( fclean(1.0+feps) > 1.0 )
  598. -    feps = 0.5*feps;
  599. -
  600. -    printf("%g\n", 2.0*feps);
  601. -}
  602. //GO.SYSIN DD fmacheps.c
  603. echo maxint.c 1>&2
  604. sed >maxint.c <<'//GO.SYSIN DD maxint.c' 's/^-//'
  605. -
  606. -/**************************************************************************
  607. -**
  608. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  609. -**
  610. -**                 Meschach Library
  611. -** 
  612. -** This Meschach Library is provided "as is" without any express 
  613. -** or implied warranty of any kind with respect to this software. 
  614. -** In particular the authors shall not be liable for any direct, 
  615. -** indirect, special, incidental or consequential damages arising 
  616. -** in any way from use of the software.
  617. -** 
  618. -** Everyone is granted permission to copy, modify and redistribute this
  619. -** Meschach Library, provided:
  620. -**  1.  All copies contain this copyright notice.
  621. -**  2.  All modified copies shall carry a notice stating who
  622. -**      made the last modification and the date of such modification.
  623. -**  3.  No charge is made for this software or works derived from it.  
  624. -**      This clause shall not be construed as constraining other software
  625. -**      distributed on the same medium as this software, nor is a
  626. -**      distribution fee considered a charge.
  627. -**
  628. -***************************************************************************/
  629. -
  630. -
  631. -main()
  632. -{
  633. -    int        i, old_i;
  634. -
  635. -    i = 1;
  636. -    while ( i > 0 )
  637. -    {
  638. -    old_i = i;
  639. -    i = (i << 1) | 1;
  640. -    }
  641. -    printf("%d\n", old_i);
  642. -}
  643. //GO.SYSIN DD maxint.c
  644. echo makefile.in 1>&2
  645. sed >makefile.in <<'//GO.SYSIN DD makefile.in' 's/^-//'
  646. -#
  647. -# Makefile for Meschach via autoconf
  648. -#
  649. -# Copyright (C) David Stewart & Zbigniew Leyk 1993
  650. -#
  651. -# $Id: makefile.in,v 1.4 1994/03/14 01:24:06 des Exp $
  652. -#
  653. -
  654. -srcdir = @srcdir@
  655. -VPATH = @srcdir@
  656. -
  657. -CC = @CC@
  658. -
  659. -DEFS = @DEFS@
  660. -LIBS = @LIBS@
  661. -RANLIB = @RANLIB@
  662. -
  663. -
  664. -CFLAGS = -O
  665. -
  666. -
  667. -.c.o:
  668. -    $(CC) -c $(CFLAGS) $(DEFS) $<
  669. -
  670. -SHELL = /bin/sh
  671. -MES_PAK = mesch12b
  672. -TAR = tar
  673. -SHAR = stree -u
  674. -ZIP = zip -r -l
  675. -FLIST = FILELIST
  676. -
  677. -###############################
  678. -
  679. -LIST1 = copy.o err.o matrixio.o memory.o vecop.o matop.o pxop.o \
  680. -    submat.o init.o otherio.o machine.o matlab.o ivecop.o version.o \
  681. -    meminfo.o memstat.o
  682. -LIST2 = lufactor.o bkpfacto.o chfactor.o qrfactor.o solve.o hsehldr.o \
  683. -    givens.o update.o norm.o hessen.o symmeig.o schur.o svd.o fft.o \
  684. -    mfunc.o bdfactor.o
  685. -LIST3 = sparse.o sprow.o sparseio.o spchfctr.o splufctr.o \
  686. -    spbkp.o spswap.o iter0.o itersym.o iternsym.o
  687. -ZLIST1 = zmachine.o zcopy.o zmatio.o zmemory.o zvecop.o zmatop.o znorm.o \
  688. -     zfunc.o 
  689. -ZLIST2 = zlufctr.o zsolve.o zmatlab.o zhsehldr.o zqrfctr.o \
  690. -         zgivens.o  zhessen.o zschur.o
  691. -
  692. -# they are no longer supported
  693. -# if you use them add oldpart to all and sparse
  694. -OLDLIST = conjgrad.o lanczos.o arnoldi.o
  695. -
  696. -ALL_LISTS = $(LIST1) $(LIST2) $(LIST3) $(ZLIST1) $(ZLIST2) $(OLDLIST)
  697. -
  698. -HBASE = err.h meminfo.h machine.h matrix.h
  699. -
  700. -HLIST = $(HBASE) iter.h matlab.h matrix2.h  oldnames.h sparse.h \
  701. -    sparse2.h  zmatrix.h zmatrix2.h
  702. -
  703. -TORTURE = torture.o sptort.o ztorture.o memtort.o itertort.o \
  704. -     mfuntort.o iotort.o
  705. -
  706. -OTHERS = dmacheps.c extras.c fmacheps.c maxint.c  makefile.in \
  707. -     README configure configure.in machine.h.in copyright \
  708. -     tutorial.c tutadv.c rk4.dat ls.dat makefile $(FLIST)
  709. -
  710. -
  711. -# Different configurations
  712. -# the dependencies **between** the parts are for dmake
  713. -all: @PROGS@ part1 part2 part3 zpart1 zpart2 
  714. -part2: part1
  715. -part3: part2
  716. -basic: part1 part2
  717. -sparse: part1 part2 part3 
  718. -zpart2: zpart1
  719. -complex: part1 part2 zpart1 zpart2
  720. -
  721. -
  722. -$(LIST1): $(HBASE)
  723. -part1: $(LIST1)
  724. -    ar ru meschach.a $(LIST1); $(RANLIB) meschach.a
  725. -
  726. -$(LIST2): $(HBASE) matrix2.h
  727. -part2: $(LIST2)
  728. -    ar ru meschach.a $(LIST2); $(RANLIB) meschach.a
  729. -
  730. -$(LIST3): $(HBASE) sparse.h sparse2.h
  731. -part3: $(LIST3)
  732. -    ar ru meschach.a $(LIST3); $(RANLIB) meschach.a
  733. -
  734. -$(ZLIST1): $(HBASDE) zmatrix.h
  735. -zpart1: $(ZLIST1)
  736. -    ar ru meschach.a $(ZLIST1); $(RANLIB) meschach.a
  737. -
  738. -$(ZLIST2): $(HBASE) zmatrix.h zmatrix2.h 
  739. -zpart2: $(ZLIST2)
  740. -    ar ru meschach.a $(ZLIST2); $(RANLIB) meschach.a
  741. -
  742. -$(OLDLIST): $(HBASE) sparse.h sparse2.h 
  743. -oldpart: $(OLDLIST)
  744. -    ar ru meschach.a $(OLDLIST); $(RANLIB) meschach.a
  745. -
  746. -
  747. -
  748. -#######################################
  749. -
  750. -tar:
  751. -    - /bin/rm -f $(MES_PAK).tar
  752. -    chmod 644 `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  753. -    $(OTHERS) $(HLIST)  `echo $(TORTURE) | sed -e 's/\.o/.c/g'` 
  754. -    chmod 755 configure
  755. -    $(MAKE) list
  756. -    $(TAR) cvf $(MES_PAK).tar \
  757. -     `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  758. -    $(HLIST)  $(OTHERS) \
  759. -    `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  760. -    MACHINES DOC
  761. -
  762. -# use this only for PC machines    
  763. -msdos-zip:
  764. -    - /bin/rm -f $(MES_PAK).zip
  765. -    chmod 644 `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  766. -    $(OTHERS) $(HLIST) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` 
  767. -    chmod 755 configure
  768. -    $(MAKE) list
  769. -    $(ZIP)  $(MES_PAK).zip \
  770. -     `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  771. -    $(HLIST)  $(OTHERS) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  772. -    MACHINES DOC
  773. -    
  774. -
  775. -fullshar:
  776. -    - /bin/rm -f $(MES_PAK).shar;
  777. -    chmod 644 `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  778. -    $(OTHERS) $(HLIST) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` 
  779. -    chmod 755 configure
  780. -    $(MAKE) list
  781. -    $(SHAR) `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  782. -    $(HLIST)  $(OTHERS) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  783. -    MACHINES DOC > $(MES_PAK).shar
  784. -
  785. -shar:
  786. -    - /bin/rm -f meschach1.shar meschach2.shar meschach3.shar \
  787. -    meschach4.shar oldmeschach.shar meschach0.shar 
  788. -    chmod 644 `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  789. -    $(OTHERS) $(HLIST) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` 
  790. -    chmod 755 configure    
  791. -    $(MAKE) list
  792. -    $(SHAR) `echo $(LIST1) | sed -e 's/\.o/.c/g'` > meschach1.shar
  793. -    $(SHAR) `echo $(LIST2) | sed -e 's/\.o/.c/g'` > meschach2.shar
  794. -    $(SHAR) `echo $(LIST3) | sed -e 's/\.o/.c/g'` > meschach3.shar    
  795. -    $(SHAR) `echo $(ZLIST1) | sed -e 's/\.o/.c/g'` \
  796. -      `echo $(ZLIST2) | sed -e 's/\.o/.c/g'` > meschach4.shar
  797. -    $(SHAR) `echo $(OLDLIST) | sed -e 's/\.o/.c/g'` > oldmeschach.shar
  798. -    $(SHAR) $(OTHERS) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  799. -      $(HLIST)  DOC MACHINES  > meschach0.shar
  800. -
  801. -list:
  802. -    /bin/rm -f $(FLIST)
  803. -    ls -lR `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  804. -    `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  805. -    $(HLIST) $(OTHERS) MACHINES DOC \
  806. -    |awk '/^$$/ {print};/^[-d]/ {printf("%s %s   %10d %s %s %s %s\n", \
  807. -     $$1,$$2,$$5,$$6,$$7,$$8,$$9)}; /^[^-d]/ {print}' \
  808. -    > $(FLIST)
  809. -
  810. -
  811. -
  812. -clean:
  813. -    /bin/rm -f *.o core asx5213a.mat iotort.dat 
  814. -
  815. -cleanup:
  816. -    /bin/rm -f *.o core asx5213a.mat iotort.dat *.a 
  817. -
  818. -realclean:
  819. -    /bin/rm -f *.o core asx5213a.mat iotort.dat *.a
  820. -    /bin/rm -f torture sptort ztorture memtort itertort mfuntort iotort
  821. -    /bin/rm -f makefile machine.h config.status maxint macheps
  822. -alltorture: torture sptort ztorture memtort itertort mfuntort iotort
  823. -
  824. -torture:torture.o meschach.a
  825. -    $(CC) $(CFLAGS) $(DEFS) -o torture torture.o \
  826. -    meschach.a $(LIBS)
  827. -sptort:sptort.o meschach.a
  828. -    $(CC) $(CFLAGS) $(DEFS) -o sptort sptort.o \
  829. -    meschach.a $(LIBS)
  830. -memtort: memtort.o meschach.a
  831. -    $(CC) $(CFLAGS) $(DEFS) -o memtort memtort.o \
  832. -    meschach.a $(LIBS)
  833. -ztorture:ztorture.o meschach.a
  834. -    $(CC) $(CFLAGS) $(DEFS) -o ztorture ztorture.o \
  835. -    meschach.a $(LIBS)
  836. -itertort: itertort.o meschach.a
  837. -    $(CC) $(CFLAGS) $(DEFS) -o itertort itertort.o \
  838. -    meschach.a $(LIBS)
  839. -
  840. -iotort: iotort.o meschach.a
  841. -    $(CC) $(CFLAGS) $(DEFS) -o iotort iotort.o \
  842. -    meschach.a $(LIBS)
  843. -mfuntort: mfuntort.o meschach.a
  844. -    $(CC) $(CFLAGS) $(DEFS) -o mfuntort mfuntort.o \
  845. -    meschach.a $(LIBS)
  846. -tstmove: tstmove.o meschach.a
  847. -    $(CC) $(CFLAGS) $(DEFS) -o tstmove tstmove.o \
  848. -    meschach.a $(LIBS)
  849. -tstpxvec: tstpxvec.o meschach.a
  850. -    $(CC) $(CFLAGS) $(DEFS) -o tstpxvec tstpxvec.o \
  851. -    meschach.a $(LIBS)
  852. -
  853. //GO.SYSIN DD makefile.in
  854. echo README 1>&2
  855. sed >README <<'//GO.SYSIN DD README' 's/^-//'
  856. -
  857. -
  858. -                     
  859. -                 Meschach Library
  860. -                   Version 1.2b
  861. -
  862. -
  863. -                 David E. Stewart
  864. -            (david.stewart@anu.edu.au)
  865. -
  866. -                    and
  867. -
  868. -                   Zbigniew Leyk
  869. -            (zbigniew.leyk@anu.edu.au)
  870. -
  871. -              School of Mathematical Sciences
  872. -              Australian National University
  873. -                 Canberra ACT 0200
  874. -                 Australia
  875. -
  876. -
  877. -              [last revised: 6th April, 1994]
  878. -
  879. -
  880. -                  1. INTRODUCTION
  881. -
  882. -   The Meschach Library is a numerical library of C routines for performing
  883. -calculations on matrices and vectors. It is intended for solving systems of
  884. -linear equations (dense and sparse), solve least squares problems,
  885. -computing eigenvalues and eigenvectors, etc. We do not claim that it
  886. -contains every useful algorithm in numerical linear algebra, but it does
  887. -provide a basis on which more advanced algorithms can be built. The library
  888. -is for people who know something about the C programming language,
  889. -something of how to solve the numerical problem they are faced with but do
  890. -not want to have the hassle of building all the necessary routines from the
  891. -scratch. The library is not a loose collection of numerical routines but it
  892. -comprises a coherent system. The current version is enhanced with many
  893. -features comparing with previous versions. Since the memory requirements
  894. -are nontrivial for large problems we have paid more attention to
  895. -allocation/deallocation of memory.
  896. -
  897. -   The source code is available to be perused, used and passed on without
  898. -cost, while ensuring that the quality of the software is not compromised.
  899. -The software is copyrighted; however, the copyright agreement follows in
  900. -the footsteps of the Free Software Foundation in preventing abuse that
  901. -occurs with totally public domain software.
  902. -
  903. -   Detailed instructions for installing Meschach are contained below.
  904. -
  905. -   Pronunciation: if in doubt, say "me-shark".  This is close enough.
  906. -Don't ask us "Why call it that?"  Have a look at the quote at the front of
  907. -the manual.
  908. -
  909. -
  910. -                  2. AVAILABILITY
  911. -
  912. -    The authors make this code openly available to others, in the hope that
  913. -it will prove to be a useful tool.  We ask only that:
  914. -
  915. -* If you publish results obtained using Meschach, please consider
  916. -  acknowledging the source of the code.
  917. -
  918. -* If you discover any errors in the code, please promptly communicate them
  919. -  to the authors.
  920. -
  921. -    We also suggest that you send email to the authors identifying yourself
  922. -as a user of Meschach; this will enable the authors to notify you of any
  923. -corrections/improvements in Meschach.
  924. -
  925. -
  926. -
  927. -                 3. HOW TO GET IT
  928. -
  929. -   There are several different forms in which you might receive Meschach.
  930. -To provide a shorthand for describing collections of files, the Unix
  931. -convention of putting alternative letters in [...] will be used.  (So,
  932. -fred[123] means the collection fred1, fred2 and fred3.)  Meschach is
  933. -available over Internet/AARnet via netlib, or at the anonymous ftp site
  934. -thrain.anu.edu.au in the directory pub/meschach.  There are five .shar
  935. -files: meschach[01234].shar (which contain the library itself),
  936. -meschach0.shar (which contains basic documentation and machine dependent
  937. -files for a number of machines).  Of the meschach[1234].shar files, only
  938. -meschach[12].shar are needed for the basic Meschach library; the third
  939. -.shar file contains the sparse matrix routines, and the the fourth contains
  940. -the routines for complex numbers, vectors and matrices.  There is also a
  941. -README file that you should get from meschach0.shar.
  942. -
  943. -   If you need the old iterative routines, the file oldmeschach.shar
  944. -contains the files conjgrad.c, arnoldi.c and lanczos.c.
  945. -
  946. -   To get the library from netlib,
  947. -
  948. -mail netlib@research.att.com
  949. -send all from c/meschach
  950. -
  951. -   There are a number of other netlib sites which mirror the main netlib
  952. -sites.  These include netlib@ornl.gov (Oak Ridge, TN, USA), netlib@nac.no
  953. -(Oslo, Norway), ftp.cs.uow.edu.au (Wollongong, Australia; ftp only),
  954. -netlib@nchc.edu.tw (Taiwan), elib.zib-berlin.de (Berlin, Germany; ftp
  955. -only).  (For anonymous ftp sites the directory containing the Meschach
  956. -.shar files is pub/netlib/c/meschach or similar, possibly depending on the
  957. -site.)
  958. -
  959. -   Meschach is available in other forms on thrain.anu.edu.au by ftp in the
  960. -directory pub/meschach.  It is available as a .tar file (mesch12a.tar for
  961. -version 1.2a), or as a collection of .shar files, or as a .zip file.  The
  962. -.tar and .zip versions each contain the entire contents of the Meschach
  963. -library.
  964. -
  965. -   There is a manual called "Meschach: Matrix Computations in C" which has
  966. -been published by
  967. -
  968. -    Centre for Mathematics and its Applications
  969. -    School of Mathematical Sciences
  970. -    Australian National University
  971. -    Canberra, ACT 0200
  972. -    Australia
  973. -
  974. -and costs A$30 (about US$22) + postage/handling.  You can order it by
  975. -writing there or you can send email messages to one of us
  976. -(david.stewart@anu.edu.au or zbigniew.leyk@anu.edu.au) and we can pass it
  977. -on.
  978. -
  979. -   If you don't have any money, as a stop gap you can get the **OLD**
  980. -manual, although it is out of date, by anonymous ftp from
  981. -
  982. -    thrain.anu.edu.au : /pub/meschach/version1.1b/bookdvi.tar [.Z or .gz]
  983. -
  984. -In addition, don't forget that the distribution includes a DOC directory
  985. -which contains tutorial.txt and fnindex.txt which are respectively, the
  986. -tutorial chapter (text version) and the function index (text version).
  987. -
  988. -
  989. -
  990. -                  4. INSTALLATION
  991. -
  992. -                a) On Unix machines
  993. -
  994. -   To extract the files from the .shar files, put them all into a suitable
  995. -directory and use
  996. -
  997. -  sh <file>.shar
  998. -
  999. -to expand the files.  (Use one sh command per file; sh *.shar will not work
  1000. -in general.)
  1001. -
  1002. -   For the .tar file, use
  1003. -
  1004. -  tar xvf mesch12a.tar
  1005. -
  1006. -and for the .zip file use
  1007. -
  1008. -  unzip mesch12a.zip
  1009. -
  1010. -   On a Unix system you can use the configure script to set up the
  1011. -machine-dependent files.  The script takes a number of options which are
  1012. -used for installing different subsets of the full Meschach.  For the basic
  1013. -system, which requires only meschach[012].shar, use
  1014. -
  1015. -  configure
  1016. -  make basic
  1017. -  make clean
  1018. -
  1019. -   For including sparse operations, which requires meschach[0123].shar, use
  1020. -
  1021. -  configure --with-sparse
  1022. -  make sparse
  1023. -  make clean
  1024. -
  1025. -  For including complex operations, which requires meschach[0124].shar, use
  1026. -
  1027. -  configure --with-complex
  1028. -  make complex
  1029. -  make clean
  1030. -
  1031. -   For including everything, which requires meschach[01234].shar, use
  1032. -
  1033. -  configure --with-all
  1034. -  make all
  1035. -  make clean
  1036. -
  1037. -  To compile the complete library in single precision (with Real equivalent
  1038. -to float), add the --with-float option to configure, use
  1039. -
  1040. -  configure --with-all --with-float
  1041. -  make all
  1042. -  make clean
  1043. -
  1044. -
  1045. -   Some Unix-like systems may have some problems with this due to bugs or
  1046. -incompatibilities in various parts of the system.  To check this use make
  1047. -torture and run torture.  In this case use the machine-dependent files from
  1048. -the machines directory.  (This is the case for RS/6000 machines, the -O
  1049. -switch results in failure of a routine in schur.c.  Compiling without the
  1050. --O switch results in correct results.)
  1051. -
  1052. -   If you have problems using configure, or you use a non-Unix system,
  1053. -check the MACHINES directory (generated by meschach0.shar) for your
  1054. -machine, operating system and/or compiler.  Save the machine dependent
  1055. -files makefile, machine.c and machine.h.  Copy those files from the
  1056. -directory for your machine to the directory where the source code is.
  1057. -
  1058. -   To link into a program prog.c, compile it using
  1059. -
  1060. -  cc -o prog_name prog.c ....(source files).... meschach.a -lm
  1061. -
  1062. -
  1063. -   This code has been mostly developed on the University of Queensland,
  1064. -Australia's Pyramid 9810 running BSD4.3.  Initial development was on a
  1065. -Zilog Zeus Z8000 machine running Zeus, a Unix workalike operating system.
  1066. -Versions have also been successfully used on various Unix machines
  1067. -including Sun 3's, IBM RT's, SPARC's and an IBM RS/6000 running AIX.  It
  1068. -has also been compiled on an IBM AT clone using Quick C.  It has been
  1069. -designed to compile under either Kernighan and Richie, (Edition 1) C and
  1070. -under ANSI C.  (And, indeed, it has been compiled in both ANSI C and
  1071. -non-ANSI C environments.)
  1072. -
  1073. -
  1074. -              b) On non-Unix machines
  1075. -
  1076. -   First look in the machines directory for your system type.  If it is
  1077. -there, then copy the machine dependent files machine.h, makefile (and
  1078. -possibly machine.c) to the Meschach directory.
  1079. -
  1080. -   If your machine type is not there, then you will need to either compile
  1081. -``by hand'', or construct your own makefile and possibly machine.h as well.
  1082. -The machine-dependent files for various systems should be used as a
  1083. -starting point, and the ``vanilla'' version of machine.h should be used.
  1084. -Information on the machine-dependent files follows in the next three
  1085. -subsections.
  1086. -
  1087. -   On an IBM PC clone, the source code would be on a floppy disk. Use
  1088. -
  1089. -  xcopy a:* meschach
  1090. -
  1091. -to copy it to the meschach directory.  Then ``cd meschach'', and then
  1092. -compile the source code.  Different compilers on MSDOS machines will
  1093. -require different installation procedures.  Check the directory meschach
  1094. -for the appropriate ``makefile'' for your compiler.  If your compiler is
  1095. -not listed, then you should try compiling it ``by hand'', modifying the
  1096. -machine-dependent files as necessary.
  1097. -
  1098. -   Worst come to worst, for a given C compiler, execute
  1099. -        <C compiler name> *.c
  1100. -on MS-DOS machines. For example,
  1101. -        tcc *.c
  1102. -for Turbo C, and
  1103. -        msc *.c
  1104. -for Microsoft C, or if you are using Quick C,
  1105. -        qcl *.c
  1106. -and of course
  1107. -        cc *.c
  1108. -for the standard Unix compiler.
  1109. -
  1110. -   Once the object files have been generated, you will need to combine them
  1111. -into a library. Consult your local compiler's manual for details of how to
  1112. -do this.
  1113. -
  1114. -   When compiling programs/routines that use Meschach, you will need to
  1115. -have access the the header files in the INCLUDE directory. The INCLUDE
  1116. -directory's contents can be copied to the directory where the
  1117. -programs/routines are compiled.
  1118. -
  1119. -   The files in the DOC directory form a very brief form of documentation
  1120. -on the the library routines in Meschach. See the printed documentation for
  1121. -more comprehensive documentation of the Meschach routines.  This can be
  1122. -obtained from the authors via email.
  1123. -
  1124. -   The files and directories created by the machines.shar shell archive
  1125. -contain the files machine.c machine.h and makefile for a particular
  1126. -machine/operating system/compiler where they need to be different.  Copy
  1127. -the files in the appropriate directory for your machine/operating
  1128. -system/compiler to the directory with the Meschach source before compiling.
  1129. -
  1130. -
  1131. -
  1132. -                   c)  makefile
  1133. -
  1134. -
  1135. -   This is setup by using the configure script on a Unix system, based on
  1136. -the makefile.in file.  However, if you want to modify how the library is
  1137. -compiled, you are free to change the makefile.
  1138. -
  1139. -   The most likely change that you would want to make to this file is to
  1140. -change the line
  1141. -
  1142. -  CFLAGS = -O
  1143. -
  1144. -to suit your particular compiler.
  1145. -
  1146. -  The code is intended to be compilable by both ANSI and non-ANSI
  1147. -compilers.
  1148. -
  1149. -   To achieve this portability without sacrificing the ANSI function
  1150. -prototypes (which are very useful for avoiding problems with passing
  1151. -parameters) there is a token ANSI_C which must be #define'd in order to
  1152. -take full advantage of ANSI C.  To do this you should do all compilations
  1153. -with
  1154. -
  1155. -  #define ANSI_C 1
  1156. -
  1157. -   This can also be done at the compilation stage with a -DANSI_C flag.
  1158. -Again, you will have to use the -DANSI_C flag or its equivalent whenever
  1159. -you compile, or insert the line
  1160. -
  1161. -  #define ANSI_C 1
  1162. -
  1163. -in machine.h, to make full use of ANSI C with this matrix library.
  1164. -
  1165. -
  1166. -                   d)  machine.h
  1167. -
  1168. -   Like makefile this is normally set up by the configure script on Unix
  1169. -machines.  However, for non-Unix systems, or if you need to set some things
  1170. -``by hand'', change machine.h.
  1171. -
  1172. -   There are a few quantities in here that should be modified to suit your
  1173. -particular compiler.  Firstly, the macros MEM_COPY() and MEM_ZERO() need to
  1174. -be correctly defined here.  The original library was compiled on BSD
  1175. -systems, and so it originally relied on bcopy() and bzero().
  1176. -
  1177. -   In machine.h you will find the definitions for using the standard ANSI C
  1178. -library routines:
  1179. -
  1180. -  /*--------------------ANSI C--------------------*/
  1181. -  #include        <stddef.h>
  1182. -  #include        <string.h>
  1183. -  #define    MEM_COPY(from,to,size)  memmove((to),(from),(size))
  1184. -  #define    MEM_ZERO(where,size)    memset((where),'\0',(size))
  1185. -
  1186. -   Delete or comment out the alternative definitions and it should compile
  1187. -correctly.  The source files containing memmove() and/or memset() are
  1188. -available by anonymous ftp from some ftp sites (try archie to discover 
  1189. -them). The files are usually called memmove.c or memset.c.
  1190. -Some ftp sites which currently (Jan '94) have a version of these files are
  1191. -munnari.oz.au (in Australia), ftp.uu.net, gatekeeper.dec.com (USA), and
  1192. -unix.hensa.ac.uk (in the UK).  The directory in which you will find
  1193. -memmove.c and memset.c typically looks like .../bsd-sources/lib/libc/...
  1194. -
  1195. -   There are two further machine-dependent quantities that should be set.
  1196. -These are machine epsilon or the unit roundoff for double precision
  1197. -arithmetic, and the maximum value produced by the rand() routine, which is
  1198. -used in rand_vec() and rand_mat().
  1199. -
  1200. -
  1201. -   The current definitions of these are
  1202. -
  1203. -  #define    MACHEPS    2.2e-16
  1204. -  #define    MAX_RAND 2.147483648e9
  1205. -
  1206. -   The value of MACHEPS should be correct for all IEEE standard double
  1207. -precision arithmetic.
  1208. -
  1209. -   However, ANSI C's <float.h> contains #define'd quantities DBL_EPSILON
  1210. -and RAND_MAX, so if you have an ANSI C compiler and headers, replace the
  1211. -above two lines of machine.h with
  1212. -
  1213. -  #include <float.h>
  1214. -  /* for Real == float */
  1215. -  #define MACHEPS DBL_EPSILON
  1216. -  #define MAX_RAND RAND_MAX
  1217. -
  1218. -   The default value given for MAX_RAND is 2^31 , as the Pyramid 9810 and
  1219. -the SPARC 2's both have 32 bit words.  There is a program macheps.c which
  1220. -is included in your source files which computes and prints out the value of
  1221. -MACHEPS for your machine.
  1222. -
  1223. -   Some other macros control some aspects of Meschach.  One of these is
  1224. -SEGMENTED which should be #define'd if you are working with a machine or
  1225. -compiler that does not allow large arrays to be allocated.  For example,
  1226. -the most common memory models for MS-DOS compilers do not allow more than
  1227. -64Kbyte to be allocated in one block.  This limits square matrices to be no
  1228. -more than 9090 .  Inserting #define SEGMENTED 1 into machine.h will mean
  1229. -that matrices are allocated a row at a time.
  1230. -
  1231. -
  1232. -
  1233. -                  4. SAMPLE TESTS
  1234. -
  1235. -    There are several programs for checking Meschach called torture
  1236. -(source: torture.c) for the dense routines, sptort (source: sptort.c) for
  1237. -the sparse routines, ztorture (source ztorture.c) for a complex version of
  1238. -torture, memtort (source memtort.c) for memory allocation/deallocation,
  1239. -itertort (source itertort.c) for iterative methods, mfuntort (source
  1240. -mfuntort.c) for computing powers of dense matrices, iotort (source
  1241. -iotort.c) for I/O routines.  These can be compiled using make by "make
  1242. -torture", "make sptort", etc.  The programs are part of meschach0.shar.
  1243. -
  1244. -
  1245. -                 5. OTHER PROBLEMS
  1246. -
  1247. -   Meschach is not a commercial package, so we do not guarantee that
  1248. -everything will be perfect or will install smoothly.  Inevitably there will
  1249. -be unforeseen problems. If you come across any bugs or inconsistencies, please
  1250. -let us know.  If you need to modify the results of the configure script, or
  1251. -need to construct your own machine.h and makefile's, please send them to
  1252. -us.  A number of people sent us the machine dependent files for Meschach 1.1,
  1253. -but with the use of configure, and the new information needed for version
  1254. -1.2, these machine dependent files don't have quite the right information.
  1255. -Hopefully, though, they are redundant.  Non-Unix platforms at present
  1256. -require ``manual'' installation.  Because of the variety of platforms
  1257. -(MS-DOS, Macintosh, VAX/VMS, Prime, Amiga, Atari, ....) this is left up to
  1258. -the users of these platforms.  We hope that you can use the distibutable
  1259. -machine-dependent files as a starting point for this task.
  1260. -
  1261. -   If you have programs or routines written using Meschach v.1.1x, you
  1262. -should put the statement
  1263. -
  1264. -   #include "oldnames.h"
  1265. -
  1266. -at the beginning of your files.  This is because a large number of the
  1267. -names of the routines have been changed (e.g. "get_vec()" has become
  1268. -"v_get()").  This will enable you to use the old names, although all of the
  1269. -error messages etc., will use the new names.  Also note that the new
  1270. -iterative routines have a very different calling sequence.  If you need the
  1271. -old iterative routines, they are in oldmeschach.shar.
  1272. -
  1273. -   If you wish to let us know what you have done, etc., our email
  1274. -addresses are
  1275. -
  1276. -             david.stewart@anu.edu.au
  1277. -             zbigniew.leyk@anu.edu.au
  1278. -
  1279. -    Good luck!
  1280. -
  1281. -                  ACKNOWLEDGMENTS
  1282. -
  1283. -
  1284. -    Many people have helped in various ways with ideas and suggestions.
  1285. -Needless to say, the bugs are all ours!  But these people should be thanked
  1286. -for their encouragement etc.  These include a number of people at
  1287. -University of Queensland: Graeme Chandler, David De Wit, Martin Sharry,
  1288. -Michael Forbes, Phil Kilby, John Holt, Phil Pollett and Tony Watts.  At the
  1289. -Australian National University: Mike Osborne, Steve Roberts, Margaret Kahn
  1290. -and Teresa Leyk.  Karen George of the University of Canberra has been a
  1291. -source of both ideas and encouragement.  Email has become significant part
  1292. -of work, and many people have pointed out bugs, inconsistencies and
  1293. -improvements to Meschach by email.  These people include Ajay Shah of the
  1294. -University of Southern California, Dov Grobgeld of the Weizmann Institute,
  1295. -John Edstrom of the University of Calgary, Eric Grosse, one of the netlib
  1296. -organisers, Ole Saether of Oslo, Norway, Alfred Thiele and Pierre
  1297. -Asselin of Carnegie-Mellon Univeristy, Daniel Polani of the University of
  1298. -Mainz, Marian Slodicka of Slovakia, Kaifu Wu of Pomona, Hidetoshi
  1299. -Shimodaira of the University of Tokyo, Eng Siong of Edinburgh, Hirokawa Rui
  1300. -of the University of Tokyo, Marko Slyz of the University of Michigan, and
  1301. -Brook Milligan of the University of Texas.  This list is only partial, and
  1302. -there are many others who have corresponded with us on details about
  1303. -Meschach and the like.  Finally our thanks go to all those that have had to
  1304. -struggle with compilers and other things to get Meschach to work.
  1305. -
  1306. -                     
  1307. -
  1308. -
  1309. -
  1310. //GO.SYSIN DD README
  1311. echo configure 1>&2
  1312. sed >configure <<'//GO.SYSIN DD configure' 's/^-//'
  1313. -#!/bin/sh
  1314. -# Guess values for system-dependent variables and create Makefiles.
  1315. -# Generated automatically using autoconf.
  1316. -# Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
  1317. -
  1318. -# This program is free software; you can redistribute it and/or modify
  1319. -# it under the terms of the GNU General Public License as published by
  1320. -# the Free Software Foundation; either version 2, or (at your option)
  1321. -# any later version.
  1322. -
  1323. -# This program is distributed in the hope that it will be useful,
  1324. -# but WITHOUT ANY WARRANTY; without even the implied warranty of
  1325. -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1326. -# GNU General Public License for more details.
  1327. -
  1328. -# You should have received a copy of the GNU General Public License
  1329. -# along with this program; if not, write to the Free Software
  1330. -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1331. -
  1332. -# Usage: configure [--srcdir=DIR] [--host=HOST] [--gas] [--nfp] [--no-create]
  1333. -#        [--prefix=PREFIX] [--exec-prefix=PREFIX] [--with-PACKAGE] [TARGET]
  1334. -# Ignores all args except --srcdir, --prefix, --exec-prefix, --no-create, and
  1335. -# --with-PACKAGE unless this script has special code to handle it.
  1336. -
  1337. -
  1338. -for arg
  1339. -do
  1340. -  # Handle --exec-prefix with a space before the argument.
  1341. -  if test x$next_exec_prefix = xyes; then exec_prefix=$arg; next_exec_prefix=
  1342. -  # Handle --host with a space before the argument.
  1343. -  elif test x$next_host = xyes; then next_host=
  1344. -  # Handle --prefix with a space before the argument.
  1345. -  elif test x$next_prefix = xyes; then prefix=$arg; next_prefix=
  1346. -  # Handle --srcdir with a space before the argument.
  1347. -  elif test x$next_srcdir = xyes; then srcdir=$arg; next_srcdir=
  1348. -  else
  1349. -    case $arg in
  1350. -     # For backward compatibility, also recognize exact --exec_prefix.
  1351. -     -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* | --exec=* | --exe=* | --ex=* | --e=*)
  1352. -    exec_prefix=`echo $arg | sed 's/[-a-z_]*=//'` ;;
  1353. -     -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- | --exec | --exe | --ex | --e)
  1354. -    next_exec_prefix=yes ;;
  1355. -
  1356. -     -gas | --gas | --ga | --g) ;;
  1357. -
  1358. -     -host=* | --host=* | --hos=* | --ho=* | --h=*) ;;
  1359. -     -host | --host | --hos | --ho | --h)
  1360. -    next_host=yes ;;
  1361. -
  1362. -     -nfp | --nfp | --nf) ;;
  1363. -
  1364. -     -no-create | --no-create | --no-creat | --no-crea | --no-cre | --no-cr | --no-c | --no- | --no)
  1365. -        no_create=1 ;;
  1366. -
  1367. -     -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
  1368. -    prefix=`echo $arg | sed 's/[-a-z_]*=//'` ;;
  1369. -     -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
  1370. -    next_prefix=yes ;;
  1371. -
  1372. -     -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=* | --s=*)
  1373. -    srcdir=`echo $arg | sed 's/[-a-z_]*=//'` ;;
  1374. -     -srcdir | --srcdir | --srcdi | --srcd | --src | --sr | --s)
  1375. -    next_srcdir=yes ;;
  1376. -
  1377. -     -with-* | --with-*)
  1378. -       package=`echo $arg|sed 's/-*with-//'`
  1379. -       # Delete all the valid chars; see if any are left.
  1380. -       if test -n "`echo $package|sed 's/[-a-zA-Z0-9_]*//g'`"; then
  1381. -         echo "configure: $package: invalid package name" >&2; exit 1
  1382. -       fi
  1383. -       eval "with_`echo $package|sed s/-/_/g`=1" ;;
  1384. -
  1385. -     -v | -verbose | --verbose | --verbos | --verbo | --verb | --ver | --ve | --v)
  1386. -       verbose=yes ;;
  1387. -
  1388. -     *) ;;
  1389. -    esac
  1390. -  fi
  1391. -done
  1392. -
  1393. -trap 'rm -f conftest* core; exit 1' 1 3 15
  1394. -
  1395. -# Needed for some versions of `tr' so that character classes in `[]' work.
  1396. -if test "${LANG+set}" = "set" ; then
  1397. -   LANG=C
  1398. -fi
  1399. -
  1400. -rm -f conftest*
  1401. -compile='${CC-cc} $CFLAGS $DEFS conftest.c -o conftest $LIBS >/dev/null 2>&1'
  1402. -
  1403. -# A filename unique to this package, relative to the directory that
  1404. -# configure is in, which we can look for to find out if srcdir is correct.
  1405. -unique_file=err.c
  1406. -
  1407. -# Find the source files, if location was not specified.
  1408. -if test -z "$srcdir"; then
  1409. -  srcdirdefaulted=yes
  1410. -  # Try the directory containing this script, then `..'.
  1411. -  prog=$0
  1412. -  confdir=`echo $prog|sed 's%/[^/][^/]*$%%'`
  1413. -  test "X$confdir" = "X$prog" && confdir=.
  1414. -  srcdir=$confdir
  1415. -  if test ! -r $srcdir/$unique_file; then
  1416. -    srcdir=..
  1417. -  fi
  1418. -fi
  1419. -if test ! -r $srcdir/$unique_file; then
  1420. -  if test x$srcdirdefaulted = xyes; then
  1421. -    echo "configure: Can not find sources in \`${confdir}' or \`..'." 1>&2
  1422. -  else
  1423. -    echo "configure: Can not find sources in \`${srcdir}'." 1>&2
  1424. -  fi
  1425. -  exit 1
  1426. -fi
  1427. -# Preserve a srcdir of `.' to avoid automounter screwups with pwd.
  1428. -# But we can't avoid them for `..', to make subdirectories work.
  1429. -case $srcdir in
  1430. -  .|/*|~*) ;;
  1431. -  *) srcdir=`cd $srcdir; pwd` ;; # Make relative path absolute.
  1432. -esac
  1433. -
  1434. -
  1435. -PROGS=""
  1436. -if test -z "$CC"; then
  1437. -  # Extract the first word of `acc', so it can be a program name with args.
  1438. -  set dummy acc; word=$2
  1439. -  echo checking for $word
  1440. -  IFS="${IFS=     }"; saveifs="$IFS"; IFS="${IFS}:"
  1441. -  for dir in $PATH; do
  1442. -    test -z "$dir" && dir=.
  1443. -    if test -f $dir/$word; then
  1444. -      CC="acc"
  1445. -      break
  1446. -    fi
  1447. -  done
  1448. -  IFS="$saveifs"
  1449. -fi
  1450. -test -z "$CC" && CC=""""
  1451. -test -n "$CC" -a -n "$verbose" && echo "    setting CC to $CC"
  1452. -
  1453. -if test -z "$CC"; then
  1454. -  # Extract the first word of `cc', so it can be a program name with args.
  1455. -  set dummy cc; word=$2
  1456. -  echo checking for $word
  1457. -  IFS="${IFS=     }"; saveifs="$IFS"; IFS="${IFS}:"
  1458. -  for dir in $PATH; do
  1459. -    test -z "$dir" && dir=.
  1460. -    if test -f $dir/$word; then
  1461. -      CC="cc"
  1462. -      break
  1463. -    fi
  1464. -  done
  1465. -  IFS="$saveifs"
  1466. -fi
  1467. -test -z "$CC" && CC="gcc"
  1468. -test -n "$CC" -a -n "$verbose" && echo "    setting CC to $CC"
  1469. -
  1470. -echo checking how to run the C preprocessor
  1471. -if test -z "$CPP"; then
  1472. -  CPP='${CC-cc} -E'
  1473. -  cat > conftest.c <<EOF
  1474. -#include <stdio.h>
  1475. -EOF
  1476. -err=`eval "($CPP \$DEFS conftest.c >/dev/null) 2>&1"`
  1477. -if test -z "$err"; then
  1478. -  :
  1479. -else
  1480. -  CPP=/lib/cpp
  1481. -fi
  1482. -rm -f conftest*
  1483. -fi
  1484. -
  1485. -echo checking for AIX
  1486. -cat > conftest.c <<EOF
  1487. -#ifdef _AIX
  1488. -  yes
  1489. -#endif
  1490. -
  1491. -EOF
  1492. -eval "$CPP \$DEFS conftest.c > conftest.out 2>&1"
  1493. -if egrep "yes" conftest.out >/dev/null 2>&1; then
  1494. -  {
  1495. -test -n "$verbose" && \
  1496. -echo '    defining' _ALL_SOURCE
  1497. -DEFS="$DEFS -D_ALL_SOURCE=1"
  1498. -SEDDEFS="${SEDDEFS}\${SEDdA}_ALL_SOURCE\${SEDdB}_ALL_SOURCE\${SEDdC}1\${SEDdD}
  1499. -\${SEDuA}_ALL_SOURCE\${SEDuB}_ALL_SOURCE\${SEDuC}1\${SEDuD}
  1500. -\${SEDeA}_ALL_SOURCE\${SEDeB}_ALL_SOURCE\${SEDeC}1\${SEDeD}
  1501. -"
  1502. -}
  1503. -
  1504. -fi
  1505. -rm -f conftest*
  1506. -
  1507. -
  1508. -echo checking for minix/config.h
  1509. -cat > conftest.c <<EOF
  1510. -#include <minix/config.h>
  1511. -EOF
  1512. -err=`eval "($CPP \$DEFS conftest.c >/dev/null) 2>&1"`
  1513. -if test -z "$err"; then
  1514. -  MINIX=1
  1515. -fi
  1516. -rm -f conftest*
  1517. -
  1518. -# The Minix shell can't assign to the same variable on the same line!
  1519. -if test -n "$MINIX"; then
  1520. -  {
  1521. -test -n "$verbose" && \
  1522. -echo '    defining' _POSIX_SOURCE
  1523. -DEFS="$DEFS -D_POSIX_SOURCE=1"
  1524. -SEDDEFS="${SEDDEFS}\${SEDdA}_POSIX_SOURCE\${SEDdB}_POSIX_SOURCE\${SEDdC}1\${SEDdD}
  1525. -\${SEDuA}_POSIX_SOURCE\${SEDuB}_POSIX_SOURCE\${SEDuC}1\${SEDuD}
  1526. -\${SEDeA}_POSIX_SOURCE\${SEDeB}_POSIX_SOURCE\${SEDeC}1\${SEDeD}
  1527. -"
  1528. -}
  1529. -
  1530. -  {
  1531. -test -n "$verbose" && \
  1532. -echo '    defining' _POSIX_1_SOURCE to be '2'
  1533. -DEFS="$DEFS -D_POSIX_1_SOURCE=2"
  1534. -SEDDEFS="${SEDDEFS}\${SEDdA}_POSIX_1_SOURCE\${SEDdB}_POSIX_1_SOURCE\${SEDdC}2\${SEDdD}
  1535. -\${SEDuA}_POSIX_1_SOURCE\${SEDuB}_POSIX_1_SOURCE\${SEDuC}2\${SEDuD}
  1536. -\${SEDeA}_POSIX_1_SOURCE\${SEDeB}_POSIX_1_SOURCE\${SEDeC}2\${SEDeD}
  1537. -"
  1538. -}
  1539. -
  1540. -  {
  1541. -test -n "$verbose" && \
  1542. -echo '    defining' _MINIX
  1543. -DEFS="$DEFS -D_MINIX=1"
  1544. -SEDDEFS="${SEDDEFS}\${SEDdA}_MINIX\${SEDdB}_MINIX\${SEDdC}1\${SEDdD}
  1545. -\${SEDuA}_MINIX\${SEDuB}_MINIX\${SEDuC}1\${SEDuD}
  1546. -\${SEDeA}_MINIX\${SEDeB}_MINIX\${SEDeC}1\${SEDeD}
  1547. -"
  1548. -}
  1549. -
  1550. -fi
  1551. -
  1552. -echo checking for POSIXized ISC
  1553. -if test -d /etc/conf/kconfig.d &&
  1554. -  grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1
  1555. -then
  1556. -  ISC=1 # If later tests want to check for ISC.
  1557. -  {
  1558. -test -n "$verbose" && \
  1559. -echo '    defining' _POSIX_SOURCE
  1560. -DEFS="$DEFS -D_POSIX_SOURCE=1"
  1561. -SEDDEFS="${SEDDEFS}\${SEDdA}_POSIX_SOURCE\${SEDdB}_POSIX_SOURCE\${SEDdC}1\${SEDdD}
  1562. -\${SEDuA}_POSIX_SOURCE\${SEDuB}_POSIX_SOURCE\${SEDuC}1\${SEDuD}
  1563. -\${SEDeA}_POSIX_SOURCE\${SEDeB}_POSIX_SOURCE\${SEDeC}1\${SEDeD}
  1564. -"
  1565. -}
  1566. -
  1567. -  if test -n "$GCC"; then
  1568. -    CC="$CC -posix"
  1569. -  else
  1570. -    CC="$CC -Xp"
  1571. -  fi
  1572. -fi
  1573. -
  1574. -if test -z "$RANLIB"; then
  1575. -  # Extract the first word of `ranlib', so it can be a program name with args.
  1576. -  set dummy ranlib; word=$2
  1577. -  echo checking for $word
  1578. -  IFS="${IFS=     }"; saveifs="$IFS"; IFS="${IFS}:"
  1579. -  for dir in $PATH; do
  1580. -    test -z "$dir" && dir=.
  1581. -    if test -f $dir/$word; then
  1582. -      RANLIB="ranlib"
  1583. -      break
  1584. -    fi
  1585. -  done
  1586. -  IFS="$saveifs"
  1587. -fi
  1588. -test -z "$RANLIB" && RANLIB=":"
  1589. -test -n "$RANLIB" -a -n "$verbose" && echo "    setting RANLIB to $RANLIB"
  1590. -
  1591. -for hdr in memory.h
  1592. -do
  1593. -trhdr=HAVE_`echo $hdr | tr '[a-z]./' '[A-Z]__'`
  1594. -echo checking for ${hdr}
  1595. -cat > conftest.c <<EOF
  1596. -#include <${hdr}>
  1597. -EOF
  1598. -err=`eval "($CPP \$DEFS conftest.c >/dev/null) 2>&1"`
  1599. -if test -z "$err"; then
  1600. -  {
  1601. -test -n "$verbose" && \
  1602. -echo '    defining' ${trhdr}
  1603. -DEFS="$DEFS -D${trhdr}=1"
  1604. -SEDDEFS="${SEDDEFS}\${SEDdA}${trhdr}\${SEDdB}${trhdr}\${SEDdC}1\${SEDdD}
  1605. -\${SEDuA}${trhdr}\${SEDuB}${trhdr}\${SEDuC}1\${SEDuD}
  1606. -\${SEDeA}${trhdr}\${SEDeB}${trhdr}\${SEDeC}1\${SEDeD}
  1607. -"
  1608. -}
  1609. -
  1610. -fi
  1611. -rm -f conftest*
  1612. -done
  1613. -
  1614. -echo checking for ANSI C header files
  1615. -cat > conftest.c <<EOF
  1616. -#include <stdlib.h>
  1617. -#include <stdarg.h>
  1618. -#include <string.h>
  1619. -#include <float.h>
  1620. -EOF
  1621. -err=`eval "($CPP \$DEFS conftest.c >/dev/null) 2>&1"`
  1622. -if test -z "$err"; then
  1623. -  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
  1624. -echo '#include <string.h>' > conftest.c
  1625. -eval "$CPP \$DEFS conftest.c > conftest.out 2>&1"
  1626. -if egrep "memchr" conftest.out >/dev/null 2>&1; then
  1627. -  # SGI's /bin/cc from Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
  1628. -cat > conftest.c <<EOF
  1629. -#include <ctype.h>
  1630. -#define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
  1631. -#define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
  1632. -#define XOR(e,f) (((e) && !(f)) || (!(e) && (f)))
  1633. -int main () { int i; for (i = 0; i < 256; i++)
  1634. -if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2);
  1635. -exit (0); }
  1636. -
  1637. -EOF
  1638. -eval $compile
  1639. -if test -s conftest && (./conftest; exit) 2>/dev/null; then
  1640. -  {
  1641. -test -n "$verbose" && \
  1642. -echo '    defining' STDC_HEADERS
  1643. -DEFS="$DEFS -DSTDC_HEADERS=1"
  1644. -SEDDEFS="${SEDDEFS}\${SEDdA}STDC_HEADERS\${SEDdB}STDC_HEADERS\${SEDdC}1\${SEDdD}
  1645. -\${SEDuA}STDC_HEADERS\${SEDuB}STDC_HEADERS\${SEDuC}1\${SEDuD}
  1646. -\${SEDeA}STDC_HEADERS\${SEDeB}STDC_HEADERS\${SEDeC}1\${SEDeD}
  1647. -"
  1648. -}
  1649. -
  1650. -fi
  1651. -rm -f conftest*
  1652. -fi
  1653. -rm -f conftest*
  1654. -
  1655. -fi
  1656. -rm -f conftest*
  1657. -
  1658. -echo checking for complex.h
  1659. -cat > conftest.c <<EOF
  1660. -#include <complex.h>
  1661. -EOF
  1662. -err=`eval "($CPP \$DEFS conftest.c >/dev/null) 2>&1"`
  1663. -if test -z "$err"; then
  1664. -  {
  1665. -test -n "$verbose" && \
  1666. -echo '    defining' HAVE_COMPLEX_H
  1667. -DEFS="$DEFS -DHAVE_COMPLEX_H=1"
  1668. -SEDDEFS="${SEDDEFS}\${SEDdA}HAVE_COMPLEX_H\${SEDdB}HAVE_COMPLEX_H\${SEDdC}1\${SEDdD}
  1669. -\${SEDuA}HAVE_COMPLEX_H\${SEDuB}HAVE_COMPLEX_H\${SEDuC}1\${SEDuD}
  1670. -\${SEDeA}HAVE_COMPLEX_H\${SEDeB}HAVE_COMPLEX_H\${SEDeC}1\${SEDeD}
  1671. -"
  1672. -}
  1673. -
  1674. -fi
  1675. -rm -f conftest*
  1676. -
  1677. -echo checking for malloc.h
  1678. -cat > conftest.c <<EOF
  1679. -#include <malloc.h>
  1680. -EOF
  1681. -err=`eval "($CPP \$DEFS conftest.c >/dev/null) 2>&1"`
  1682. -if test -z "$err"; then
  1683. -  {
  1684. -test -n "$verbose" && \
  1685. -echo '    defining' HAVE_MALLOC_H
  1686. -DEFS="$DEFS -DHAVE_MALLOC_H=1"
  1687. -SEDDEFS="${SEDDEFS}\${SEDdA}HAVE_MALLOC_H\${SEDdB}HAVE_MALLOC_H\${SEDdC}1\${SEDdD}
  1688. -\${SEDuA}HAVE_MALLOC_H\${SEDuB}HAVE_MALLOC_H\${SEDuC}1\${SEDuD}
  1689. -\${SEDeA}HAVE_MALLOC_H\${SEDeB}HAVE_MALLOC_H\${SEDeC}1\${SEDeD}
  1690. -"
  1691. -}
  1692. -
  1693. -fi
  1694. -rm -f conftest*
  1695. -
  1696. -echo checking for varargs.h
  1697. -cat > conftest.c <<EOF
  1698. -#include <varargs.h>
  1699. -EOF
  1700. -err=`eval "($CPP \$DEFS conftest.c >/dev/null) 2>&1"`
  1701. -if test -z "$err"; then
  1702. -  {
  1703. -test -n "$verbose" && \
  1704. -echo '    defining' VARARGS
  1705. -DEFS="$DEFS -DVARARGS=1"
  1706. -SEDDEFS="${SEDDEFS}\${SEDdA}VARARGS\${SEDdB}VARARGS\${SEDdC}1\${SEDdD}
  1707. -\${SEDuA}VARARGS\${SEDuB}VARARGS\${SEDuC}1\${SEDuD}
  1708. -\${SEDeA}VARARGS\${SEDeB}VARARGS\${SEDeC}1\${SEDeD}
  1709. -"
  1710. -}
  1711. -
  1712. -fi
  1713. -rm -f conftest*
  1714. -
  1715. -{
  1716. -test -n "$verbose" && \
  1717. -echo '    defining' NOT_SEGMENTED
  1718. -DEFS="$DEFS -DNOT_SEGMENTED=1"
  1719. -SEDDEFS="${SEDDEFS}\${SEDdA}NOT_SEGMENTED\${SEDdB}NOT_SEGMENTED\${SEDdC}1\${SEDdD}
  1720. -\${SEDuA}NOT_SEGMENTED\${SEDuB}NOT_SEGMENTED\${SEDuC}1\${SEDuD}
  1721. -\${SEDeA}NOT_SEGMENTED\${SEDeB}NOT_SEGMENTED\${SEDeC}1\${SEDeD}
  1722. -"
  1723. -}
  1724. -
  1725. -echo checking for size_t in sys/types.h
  1726. -echo '#include <sys/types.h>' > conftest.c
  1727. -eval "$CPP \$DEFS conftest.c > conftest.out 2>&1"
  1728. -if egrep "size_t" conftest.out >/dev/null 2>&1; then
  1729. -  :
  1730. -else
  1731. -  {
  1732. -test -n "$verbose" && \
  1733. -echo '    defining' size_t to be 'unsigned'
  1734. -DEFS="$DEFS -Dsize_t=unsigned"
  1735. -SEDDEFS="${SEDDEFS}\${SEDdA}size_t\${SEDdB}size_t\${SEDdC}unsigned\${SEDdD}
  1736. -\${SEDuA}size_t\${SEDuB}size_t\${SEDuC}unsigned\${SEDuD}
  1737. -\${SEDeA}size_t\${SEDeB}size_t\${SEDeC}unsigned\${SEDeD}
  1738. -"
  1739. -}
  1740. -
  1741. -fi
  1742. -rm -f conftest*
  1743. -
  1744. -prog='/* Ultrix mips cc rejects this.  */
  1745. -typedef int charset[2]; const charset x;
  1746. -/* SunOS 4.1.1 cc rejects this.  */
  1747. -char const *const *ccp;
  1748. -char **p;
  1749. -/* AIX XL C 1.02.0.0 rejects this.
  1750. -   It does not let you subtract one const X* pointer from another in an arm
  1751. -   of an if-expression whose if-part is not a constant expression */
  1752. -const char *g = "string";
  1753. -p = &g + (g ? g-g : 0);
  1754. -/* HPUX 7.0 cc rejects these. */
  1755. -++ccp;
  1756. -p = (char**) ccp;
  1757. -ccp = (char const *const *) p;
  1758. -{ /* SCO 3.2v4 cc rejects this.  */
  1759. -  char *t;
  1760. -  char const *s = 0 ? (char *) 0 : (char const *) 0;
  1761. -
  1762. -  *t++ = 0;
  1763. -}
  1764. -{ /* Someone thinks the Sun supposedly-ANSI compiler will reject this.  */
  1765. -  int x[] = {25,17};
  1766. -  const int *foo = &x[0];
  1767. -  ++foo;
  1768. -}
  1769. -{ /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
  1770. -  typedef const int *iptr;
  1771. -  iptr p = 0;
  1772. -  ++p;
  1773. -}
  1774. -{ /* AIX XL C 1.02.0.0 rejects this saying
  1775. -     "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
  1776. -  struct s { int j; const int *ap[3]; };
  1777. -  struct s *b; b->j = 5;
  1778. -}'
  1779. -echo checking for working const
  1780. -cat > conftest.c <<EOF
  1781. -
  1782. -int main() { exit(0); }
  1783. -int t() { $prog }
  1784. -EOF
  1785. -if eval $compile; then
  1786. -  :
  1787. -else
  1788. -  {
  1789. -test -n "$verbose" && \
  1790. -echo '    defining' const to be 'empty'
  1791. -DEFS="$DEFS -Dconst="
  1792. -SEDDEFS="${SEDDEFS}\${SEDdA}const\${SEDdB}const\${SEDdC}\${SEDdD}
  1793. -\${SEDuA}const\${SEDuB}const\${SEDuC}\${SEDuD}
  1794. -\${SEDeA}const\${SEDeB}const\${SEDeC}\${SEDeD}
  1795. -"
  1796. -}
  1797. -
  1798. -fi
  1799. -rm -f conftest*
  1800. -
  1801. -echo checking byte ordering
  1802. -cat > conftest.c <<EOF
  1803. -main () {
  1804. -  /* Are we little or big endian?  From Harbison&Steele.  */
  1805. -  union
  1806. -  {
  1807. -    long l;
  1808. -    char c[sizeof (long)];
  1809. -  } u;
  1810. -  u.l = 1;
  1811. -  exit (u.c[sizeof (long) - 1] == 1);
  1812. -}
  1813. -EOF
  1814. -eval $compile
  1815. -if test -s conftest && (./conftest; exit) 2>/dev/null; then
  1816. -  :
  1817. -else
  1818. -  {
  1819. -test -n "$verbose" && \
  1820. -echo '    defining' WORDS_BIGENDIAN
  1821. -DEFS="$DEFS -DWORDS_BIGENDIAN=1"
  1822. -SEDDEFS="${SEDDEFS}\${SEDdA}WORDS_BIGENDIAN\${SEDdB}WORDS_BIGENDIAN\${SEDdC}1\${SEDdD}
  1823. -\${SEDuA}WORDS_BIGENDIAN\${SEDuB}WORDS_BIGENDIAN\${SEDuC}1\${SEDuD}
  1824. -\${SEDeA}WORDS_BIGENDIAN\${SEDeB}WORDS_BIGENDIAN\${SEDeC}1\${SEDeD}
  1825. -"
  1826. -}
  1827. -
  1828. -fi
  1829. -rm -f conftest*
  1830. -
  1831. -# check whether --with-complex was given
  1832. -if test -n "$with_complex"; then
  1833. -  {
  1834. -test -n "$verbose" && \
  1835. -echo '    defining' COMPLEX
  1836. -DEFS="$DEFS -DCOMPLEX=1"
  1837. -SEDDEFS="${SEDDEFS}\${SEDdA}COMPLEX\${SEDdB}COMPLEX\${SEDdC}1\${SEDdD}
  1838. -\${SEDuA}COMPLEX\${SEDuB}COMPLEX\${SEDuC}1\${SEDuD}
  1839. -\${SEDeA}COMPLEX\${SEDeB}COMPLEX\${SEDeC}1\${SEDeD}
  1840. -"
  1841. -}
  1842. -
  1843. -fi
  1844. -
  1845. -# check whether --with-sparse was given
  1846. -if test -n "$with_sparse"; then
  1847. -  {
  1848. -test -n "$verbose" && \
  1849. -echo '    defining' SPARSE
  1850. -DEFS="$DEFS -DSPARSE=1"
  1851. -SEDDEFS="${SEDDEFS}\${SEDdA}SPARSE\${SEDdB}SPARSE\${SEDdC}1\${SEDdD}
  1852. -\${SEDuA}SPARSE\${SEDuB}SPARSE\${SEDuC}1\${SEDuD}
  1853. -\${SEDeA}SPARSE\${SEDeB}SPARSE\${SEDeC}1\${SEDeD}
  1854. -"
  1855. -}
  1856. -
  1857. -fi
  1858. -
  1859. -# check whether --with-all was given
  1860. -if test -n "$with_all"; then
  1861. -  {
  1862. -test -n "$verbose" && \
  1863. -echo '    defining' COMPLEX
  1864. -DEFS="$DEFS -DCOMPLEX=1"
  1865. -SEDDEFS="${SEDDEFS}\${SEDdA}COMPLEX\${SEDdB}COMPLEX\${SEDdC}1\${SEDdD}
  1866. -\${SEDuA}COMPLEX\${SEDuB}COMPLEX\${SEDuC}1\${SEDuD}
  1867. -\${SEDeA}COMPLEX\${SEDeB}COMPLEX\${SEDeC}1\${SEDeD}
  1868. -"
  1869. -}
  1870. -
  1871. -fi
  1872. -
  1873. -# check whether --with-all was given
  1874. -if test -n "$with_all"; then
  1875. -  {
  1876. -test -n "$verbose" && \
  1877. -echo '    defining' SPARSE
  1878. -DEFS="$DEFS -DSPARSE=1"
  1879. -SEDDEFS="${SEDDEFS}\${SEDdA}SPARSE\${SEDdB}SPARSE\${SEDdC}1\${SEDdD}
  1880. -\${SEDuA}SPARSE\${SEDuB}SPARSE\${SEDuC}1\${SEDuD}
  1881. -\${SEDeA}SPARSE\${SEDeB}SPARSE\${SEDeC}1\${SEDeD}
  1882. -"
  1883. -}
  1884. -
  1885. -fi
  1886. -
  1887. -# check whether --with-unroll was given
  1888. -if test -n "$with_unroll"; then
  1889. -  {
  1890. -test -n "$verbose" && \
  1891. -echo '    defining' VUNROLL
  1892. -DEFS="$DEFS -DVUNROLL=1"
  1893. -SEDDEFS="${SEDDEFS}\${SEDdA}VUNROLL\${SEDdB}VUNROLL\${SEDdC}1\${SEDdD}
  1894. -\${SEDuA}VUNROLL\${SEDuB}VUNROLL\${SEDuC}1\${SEDuD}
  1895. -\${SEDeA}VUNROLL\${SEDeB}VUNROLL\${SEDeC}1\${SEDeD}
  1896. -"
  1897. -}
  1898. -
  1899. -fi
  1900. -
  1901. -# check whether --with-munroll was given
  1902. -if test -n "$with_munroll"; then
  1903. -  {
  1904. -test -n "$verbose" && \
  1905. -echo '    defining' MUNROLL
  1906. -DEFS="$DEFS -DMUNROLL=1"
  1907. -SEDDEFS="${SEDDEFS}\${SEDdA}MUNROLL\${SEDdB}MUNROLL\${SEDdC}1\${SEDdD}
  1908. -\${SEDuA}MUNROLL\${SEDuB}MUNROLL\${SEDuC}1\${SEDuD}
  1909. -\${SEDeA}MUNROLL\${SEDeB}MUNROLL\${SEDeC}1\${SEDeD}
  1910. -"
  1911. -}
  1912. -
  1913. -fi
  1914. -
  1915. -# check whether --with-segmem was given
  1916. -if test -n "$with_segmem"; then
  1917. -  {
  1918. -test -n "$verbose" && \
  1919. -echo '    defining' SEGMENTED
  1920. -DEFS="$DEFS -DSEGMENTED=1"
  1921. -SEDDEFS="${SEDDEFS}\${SEDdA}SEGMENTED\${SEDdB}SEGMENTED\${SEDdC}1\${SEDdD}
  1922. -\${SEDuA}SEGMENTED\${SEDuB}SEGMENTED\${SEDuC}1\${SEDuD}
  1923. -\${SEDeA}SEGMENTED\${SEDeB}SEGMENTED\${SEDeC}1\${SEDeD}
  1924. -"
  1925. -}
  1926. -
  1927. -fi
  1928. -
  1929. -# check whether --with-float was given
  1930. -if test -n "$with_float"; then
  1931. -  {
  1932. -test -n "$verbose" && \
  1933. -echo '    defining' REAL_FLT
  1934. -DEFS="$DEFS -DREAL_FLT=1"
  1935. -SEDDEFS="${SEDDEFS}\${SEDdA}REAL_FLT\${SEDdB}REAL_FLT\${SEDdC}1\${SEDdD}
  1936. -\${SEDuA}REAL_FLT\${SEDuB}REAL_FLT\${SEDuC}1\${SEDuD}
  1937. -\${SEDeA}REAL_FLT\${SEDeB}REAL_FLT\${SEDeC}1\${SEDeD}
  1938. -"
  1939. -}
  1940. -
  1941. -fi
  1942. -
  1943. -# check whether --with-double was given
  1944. -if test -n "$with_double"; then
  1945. -  {
  1946. -test -n "$verbose" && \
  1947. -echo '    defining' REAL_DBL
  1948. -DEFS="$DEFS -DREAL_DBL=1"
  1949. -SEDDEFS="${SEDDEFS}\${SEDdA}REAL_DBL\${SEDdB}REAL_DBL\${SEDdC}1\${SEDdD}
  1950. -\${SEDuA}REAL_DBL\${SEDuB}REAL_DBL\${SEDuC}1\${SEDuD}
  1951. -\${SEDeA}REAL_DBL\${SEDeB}REAL_DBL\${SEDeC}1\${SEDeD}
  1952. -"
  1953. -}
  1954. -
  1955. -fi
  1956. -
  1957. -LIBS="$LIBS -lm"
  1958. -echo checking for u_int
  1959. -cat > conftest.c <<EOF
  1960. -#include <stdio.h>
  1961. -#ifdef __STDC__
  1962. -#include <stdlib.h>
  1963. -#endif
  1964. -int main() { exit(0); }
  1965. -int t() { u_int i; i = 1; }
  1966. -EOF
  1967. -if eval $compile; then
  1968. -  {
  1969. -test -n "$verbose" && \
  1970. -echo '    defining' U_INT_DEF
  1971. -DEFS="$DEFS -DU_INT_DEF=1"
  1972. -SEDDEFS="${SEDDEFS}\${SEDdA}U_INT_DEF\${SEDdB}U_INT_DEF\${SEDdC}1\${SEDdD}
  1973. -\${SEDuA}U_INT_DEF\${SEDuB}U_INT_DEF\${SEDuC}1\${SEDuD}
  1974. -\${SEDeA}U_INT_DEF\${SEDeB}U_INT_DEF\${SEDeC}1\${SEDeD}
  1975. -"
  1976. -}
  1977. -
  1978. -fi
  1979. -rm -f conftest*
  1980. -
  1981. -echo 'computing machine epsilon(s)'
  1982. -echo $CC -o macheps dmacheps.c
  1983. -$CC -o macheps dmacheps.c
  1984. -{
  1985. -test -n "$verbose" && \
  1986. -echo '    defining' D_MACHEPS to be '`macheps`'
  1987. -DEFS="$DEFS -DD_MACHEPS=`macheps`"
  1988. -SEDDEFS="${SEDDEFS}\${SEDdA}D_MACHEPS\${SEDdB}D_MACHEPS\${SEDdC}`macheps`\${SEDdD}
  1989. -\${SEDuA}D_MACHEPS\${SEDuB}D_MACHEPS\${SEDuC}`macheps`\${SEDuD}
  1990. -\${SEDeA}D_MACHEPS\${SEDeB}D_MACHEPS\${SEDeC}`macheps`\${SEDeD}
  1991. -"
  1992. -}
  1993. -
  1994. -echo $CC -o macheps fmacheps.c
  1995. -$CC -o macheps fmacheps.c
  1996. -{
  1997. -test -n "$verbose" && \
  1998. -echo '    defining' F_MACHEPS to be '`macheps`'
  1999. -DEFS="$DEFS -DF_MACHEPS=`macheps`"
  2000. -SEDDEFS="${SEDDEFS}\${SEDdA}F_MACHEPS\${SEDdB}F_MACHEPS\${SEDdC}`macheps`\${SEDdD}
  2001. -\${SEDuA}F_MACHEPS\${SEDuB}F_MACHEPS\${SEDuC}`macheps`\${SEDuD}
  2002. -\${SEDeA}F_MACHEPS\${SEDeB}F_MACHEPS\${SEDeC}`macheps`\${SEDeD}
  2003. -"
  2004. -}
  2005. -
  2006. -echo computing M_MAX_INT
  2007. -echo $CC -o maxint maxint.c
  2008. -$CC -o maxint maxint.c
  2009. -{
  2010. -test -n "$verbose" && \
  2011. -echo '    defining' M_MAX_INT to be '`maxint`'
  2012. -DEFS="$DEFS -DM_MAX_INT=`maxint`"
  2013. -SEDDEFS="${SEDDEFS}\${SEDdA}M_MAX_INT\${SEDdB}M_MAX_INT\${SEDdC}`maxint`\${SEDdD}
  2014. -\${SEDuA}M_MAX_INT\${SEDuB}M_MAX_INT\${SEDuC}`maxint`\${SEDuD}
  2015. -\${SEDeA}M_MAX_INT\${SEDeB}M_MAX_INT\${SEDeC}`maxint`\${SEDeD}
  2016. -"
  2017. -}
  2018. -
  2019. -echo checking char '\\0' vs. float zeros
  2020. -cat > conftest.c <<EOF
  2021. -main() {
  2022. -    char    *cp = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
  2023. -    double    *dp;
  2024. -    dp = (double *)cp;
  2025. -    if ( *dp == 0.0 ) printf("yes\n");  }
  2026. -
  2027. -EOF
  2028. -eval "$CPP \$DEFS conftest.c > conftest.out 2>&1"
  2029. -if egrep "yes" conftest.out >/dev/null 2>&1; then
  2030. -  {
  2031. -test -n "$verbose" && \
  2032. -echo '    defining' CHAR0ISDBL0
  2033. -DEFS="$DEFS -DCHAR0ISDBL0=1"
  2034. -SEDDEFS="${SEDDEFS}\${SEDdA}CHAR0ISDBL0\${SEDdB}CHAR0ISDBL0\${SEDdC}1\${SEDdD}
  2035. -\${SEDuA}CHAR0ISDBL0\${SEDuB}CHAR0ISDBL0\${SEDuC}1\${SEDuD}
  2036. -\${SEDeA}CHAR0ISDBL0\${SEDeB}CHAR0ISDBL0\${SEDeC}1\${SEDeD}
  2037. -"
  2038. -}
  2039. -
  2040. -fi
  2041. -rm -f conftest*
  2042. -
  2043. -for func in bcopy bzero
  2044. -do
  2045. -trfunc=HAVE_`echo $func | tr '[a-z]' '[A-Z]'`
  2046. -echo checking for ${func}
  2047. -cat > conftest.c <<EOF
  2048. -#include <ctype.h>
  2049. -int main() { exit(0); }
  2050. -int t() { 
  2051. -/* The GNU C library defines this for functions which it implements
  2052. -    to always fail with ENOSYS.  Some functions are actually named
  2053. -    something starting with __ and the normal name is an alias.  */
  2054. -#if defined (__stub_${func}) || defined (__stub___${func})
  2055. -choke me
  2056. -#else
  2057. -/* Override any gcc2 internal prototype to avoid an error.  */
  2058. -extern char ${func}(); ${func}();
  2059. -#endif
  2060. - }
  2061. -EOF
  2062. -if eval $compile; then
  2063. -  {
  2064. -test -n "$verbose" && \
  2065. -echo '    defining' ${trfunc}
  2066. -DEFS="$DEFS -D${trfunc}=1"
  2067. -SEDDEFS="${SEDDEFS}\${SEDdA}${trfunc}\${SEDdB}${trfunc}\${SEDdC}1\${SEDdD}
  2068. -\${SEDuA}${trfunc}\${SEDuB}${trfunc}\${SEDuC}1\${SEDuD}
  2069. -\${SEDeA}${trfunc}\${SEDeB}${trfunc}\${SEDeC}1\${SEDeD}
  2070. -"
  2071. -}
  2072. -
  2073. -fi
  2074. -rm -f conftest*
  2075. -done
  2076. -
  2077. -echo checking for function prototypes
  2078. -cat > conftest.c <<EOF
  2079. -
  2080. -int main() { exit(0); }
  2081. -int t() { extern int test (int i, double x); }
  2082. -EOF
  2083. -if eval $compile; then
  2084. -  {
  2085. -test -n "$verbose" && \
  2086. -echo '    defining' HAVE_PROTOTYPES
  2087. -DEFS="$DEFS -DHAVE_PROTOTYPES=1"
  2088. -SEDDEFS="${SEDDEFS}\${SEDdA}HAVE_PROTOTYPES\${SEDdB}HAVE_PROTOTYPES\${SEDdC}1\${SEDdD}
  2089. -\${SEDuA}HAVE_PROTOTYPES\${SEDuB}HAVE_PROTOTYPES\${SEDuC}1\${SEDuD}
  2090. -\${SEDeA}HAVE_PROTOTYPES\${SEDeB}HAVE_PROTOTYPES\${SEDeC}1\${SEDeD}
  2091. -"
  2092. -}
  2093. -
  2094. -fi
  2095. -rm -f conftest*
  2096. -
  2097. -if test -n "$prefix"; then
  2098. -  test -z "$exec_prefix" && exec_prefix='${prefix}'
  2099. -  prsub="s%^prefix\\([     ]*\\)=\\([     ]*\\).*$%prefix\\1=\\2$prefix%"
  2100. -fi
  2101. -if test -n "$exec_prefix"; then
  2102. -  prsub="$prsub
  2103. -s%^exec_prefix\\([     ]*\\)=\\([     ]*\\).*$%\
  2104. -exec_prefix\\1=\\2$exec_prefix%"
  2105. -fi
  2106. -DEFS="`echo \"$DEFS\" | sed 's%[&\\\]%\\\&%g'`"
  2107. -
  2108. -trap 'rm -f config.status; exit 1' 1 3 15
  2109. -echo creating config.status
  2110. -rm -f config.status
  2111. -cat > config.status <<EOF
  2112. -#!/bin/sh
  2113. -# Generated automatically by configure.
  2114. -# Run this file to recreate the current configuration.
  2115. -# This directory was configured as follows,
  2116. -# on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
  2117. -#
  2118. -# $0 $*
  2119. -
  2120. -for arg
  2121. -do
  2122. -  case "\$arg" in
  2123. -    -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
  2124. -    exec /bin/sh $0 $* ;;
  2125. -    *) echo "Usage: config.status --recheck" 2>&1; exit 1 ;;
  2126. -  esac
  2127. -done
  2128. -
  2129. -trap 'rm -f makefile machine.h conftest*; exit 1' 1 3 15
  2130. -PROGS='$PROGS'
  2131. -CC='$CC'
  2132. -CPP='$CPP'
  2133. -RANLIB='$RANLIB'
  2134. -LIBS='$LIBS'
  2135. -srcdir='$srcdir'
  2136. -prefix='$prefix'
  2137. -exec_prefix='$exec_prefix'
  2138. -prsub='$prsub'
  2139. -EOF
  2140. -cat >> config.status <<\EOF
  2141. -
  2142. -top_srcdir=$srcdir
  2143. -
  2144. -# Allow make-time overrides of the generated file list.
  2145. -test -n "$gen_files" || gen_files="makefile"
  2146. -
  2147. -for file in .. $gen_files; do if [ "x$file" != "x.." ]; then
  2148. -  srcdir=$top_srcdir
  2149. -  # Remove last slash and all that follows it.  Not all systems have dirname.
  2150. -  dir=`echo $file|sed 's%/[^/][^/]*$%%'`
  2151. -  if test "$dir" != "$file"; then
  2152. -    test "$top_srcdir" != . && srcdir=$top_srcdir/$dir
  2153. -    test ! -d $dir && mkdir $dir
  2154. -  fi
  2155. -  echo creating $file
  2156. -  rm -f $file
  2157. -  echo "# Generated automatically from `echo $file|sed 's|.*/||'`.in by configure." > $file
  2158. -  sed -e "
  2159. -$prsub
  2160. -s%@PROGS@%$PROGS%g
  2161. -s%@CC@%$CC%g
  2162. -s%@CPP@%$CPP%g
  2163. -s%@RANLIB@%$RANLIB%g
  2164. -s%@LIBS@%$LIBS%g
  2165. -s%@srcdir@%$srcdir%g
  2166. -s%@DEFS@%-DHAVE_CONFIG_H%" $top_srcdir/${file}.in >> $file
  2167. -fi; done
  2168. -test -n "$gen_config" || gen_config=machine.h
  2169. -echo creating $gen_config
  2170. -# These sed commands are put into SEDDEFS when defining a macro.
  2171. -# They are broken into pieces to make the sed script easier to manage.
  2172. -# They are passed to sed as "A NAME B NAME C VALUE D", where NAME
  2173. -# is the cpp macro being defined and VALUE is the value it is being given.
  2174. -# Each defining turns into a single global substitution command.
  2175. -#
  2176. -# SEDd sets the value in "#define NAME VALUE" lines.
  2177. -SEDdA='s@^\([     ]*\)#\([     ]*define[     ][     ]*\)'
  2178. -SEDdB='\([     ][     ]*\)[^     ]*@\1#\2'
  2179. -SEDdC='\3'
  2180. -SEDdD='@g'
  2181. -# SEDu turns "#undef NAME" with trailing blanks into "#define NAME VALUE".
  2182. -SEDuA='s@^\([     ]*\)#\([     ]*\)undef\([     ][     ]*\)'
  2183. -SEDuB='\([     ]\)@\1#\2define\3'
  2184. -SEDuC=' '
  2185. -SEDuD='\4@g'
  2186. -# SEDe turns "#undef NAME" without trailing blanks into "#define NAME VALUE".
  2187. -SEDeA='s@^\([     ]*\)#\([     ]*\)undef\([     ][     ]*\)'
  2188. -SEDeB='$@\1#\2define\3'
  2189. -SEDeC=' '
  2190. -SEDeD='@g'
  2191. -rm -f conftest.sed
  2192. -EOF
  2193. -# Turn off quoting long enough to insert the sed commands.
  2194. -rm -f conftest.sh
  2195. -cat > conftest.sh <<EOF
  2196. -$SEDDEFS
  2197. -EOF
  2198. -
  2199. -# Maximum number of lines to put in a single here document.
  2200. -maxshlines=9
  2201. -
  2202. -# Break up $SEDDEFS (now in conftest.sh) because some shells have a limit
  2203. -# on the size of here documents.
  2204. -
  2205. -while :
  2206. -do
  2207. -  lines=`grep -c . conftest.sh`
  2208. -  if test -z "$lines" || test "$lines" -eq 0; then break; fi
  2209. -  rm -f conftest.s1 conftest.s2
  2210. -  sed ${maxshlines}q conftest.sh > conftest.s1 # Like head -20.
  2211. -  sed 1,${maxshlines}d conftest.sh > conftest.s2 # Like tail +21.
  2212. -  # Write a limited-size here document to append to conftest.sed.
  2213. -  echo 'cat >> conftest.sed <<CONFEOF' >> config.status
  2214. -  cat conftest.s1 >> config.status
  2215. -  echo 'CONFEOF' >> config.status
  2216. -  rm -f conftest.s1 conftest.sh
  2217. -  mv conftest.s2 conftest.sh
  2218. -done
  2219. -rm -f conftest.sh
  2220. -
  2221. -# Now back to your regularly scheduled config.status.
  2222. -cat >> config.status <<\EOF
  2223. -# This sed command replaces #undef's with comments.  This is necessary, for
  2224. -# example, in the case of _POSIX_SOURCE, which is predefined and required
  2225. -# on some systems where configure will not decide to define it in
  2226. -# machine.h.
  2227. -cat >> conftest.sed <<\CONFEOF
  2228. -s,^[     ]*#[     ]*undef[     ][     ]*[a-zA-Z_][a-zA-Z_0-9]*,/* & */,
  2229. -CONFEOF
  2230. -rm -f conftest.h
  2231. -# Break up the sed commands because old seds have small limits.
  2232. -maxsedlines=20
  2233. -cp $top_srcdir/$gen_config.in conftest.h1
  2234. -while :
  2235. -do
  2236. -  lines=`grep -c . conftest.sed`
  2237. -  if test -z "$lines" || test "$lines" -eq 0; then break; fi
  2238. -  rm -f conftest.s1 conftest.s2 conftest.h2
  2239. -  sed ${maxsedlines}q conftest.sed > conftest.s1 # Like head -20.
  2240. -  sed 1,${maxsedlines}d conftest.sed > conftest.s2 # Like tail +21.
  2241. -  sed -f conftest.s1 < conftest.h1 > conftest.h2
  2242. -  rm -f conftest.s1 conftest.h1 conftest.sed
  2243. -  mv conftest.h2 conftest.h1
  2244. -  mv conftest.s2 conftest.sed
  2245. -done
  2246. -rm -f conftest.sed conftest.h
  2247. -echo "/* $gen_config.  Generated automatically by configure.  */" > conftest.h
  2248. -cat conftest.h1 >> conftest.h
  2249. -rm -f conftest.h1
  2250. -if cmp -s $gen_config conftest.h 2>/dev/null; then
  2251. -  # The file exists and we would not be changing it.
  2252. -  rm -f conftest.h
  2253. -else
  2254. -  rm -f $gen_config
  2255. -  mv conftest.h $gen_config
  2256. -fi
  2257. -
  2258. -
  2259. -exit 0
  2260. -EOF
  2261. -chmod +x config.status
  2262. -test -n "$no_create" || ./config.status
  2263. -
  2264. -echo "Extensions to basic version: use configure --with-opt1 --with-opt2"
  2265. -echo "  Option:"
  2266. -echo "    --with-complex     incorporate complex functions"
  2267. -echo "    --with-sparse      incorporate sparse matrix functions"
  2268. -echo "    --with-all         both of the above"
  2269. -echo "    --with-unroll      unroll low level loops on vectors"
  2270. -echo "    --with-munroll     unroll low level loops on matrices"
  2271. -echo "    --with-float       single precision"
  2272. -echo "    --with-double      double precision (default)"
  2273. -echo "Re-run configure with these options if you want them"
  2274. -# configure.in copyright (C) Brook Milligan and David Stewart, 1993
  2275. //GO.SYSIN DD configure
  2276. chmod +x configure
  2277. echo configure.in 1>&2
  2278. sed >configure.in <<'//GO.SYSIN DD configure.in' 's/^-//'
  2279. -dnl Meschach autoconf script
  2280. -dnl Copyright (C) Brook Milligan and David Stewart, 1993
  2281. -dnl $Id: configure.in,v 1.3 1994/03/08 05:41:32 des Exp $
  2282. -dnl
  2283. -dnl Brook Milligan's prototype check
  2284. -dnl Check if $(CC) supports prototypes
  2285. -define(LOCAL_HAVE_PROTOTYPES,
  2286. -[AC_COMPILE_CHECK([function prototypes], ,
  2287. -[extern int test (int i, double x);],
  2288. -AC_DEFINE(HAVE_PROTOTYPES))])dnl
  2289. -dnl
  2290. -dnl Brook Milligan's compiler check
  2291. -dnl Check for the sun ansi c compiler, acc
  2292. -define(LOCAL_PROG_ACC,
  2293. -[AC_BEFORE([$0], [AC_PROG_CPP])AC_PROVIDE([$0])dnl
  2294. -AC_PROGRAM_CHECK(CC, acc, acc, "")])dnl
  2295. -dnl David Stewart's modified compiler check
  2296. -define(LOCAL_PROG_CC,
  2297. -[AC_BEFORE([$0], [AC_PROG_CPP])AC_PROVIDE([$0])dnl
  2298. -AC_PROGRAM_CHECK(CC, acc, acc, cc)])dnl
  2299. -dnl
  2300. -dnl
  2301. -dnl
  2302. -dnl ----------------------------------------------------------------------
  2303. -dnl Start of configure.in proper
  2304. -dnl ----------------------------------------------------------------------
  2305. -AC_INIT(err.c)
  2306. -AC_CONFIG_HEADER(machine.h)
  2307. -PROGS=""
  2308. -AC_SUBST(PROGS)dnl
  2309. -LOCAL_PROG_ACC
  2310. -AC_PROGRAM_CHECK(CC, cc, cc, gcc)
  2311. -dnl AC_PROG_CC
  2312. -AC_PROG_CPP
  2313. -AC_AIX
  2314. -AC_MINIX
  2315. -AC_ISC_POSIX
  2316. -dnl
  2317. -dnl Brook Milligan's prototype check
  2318. -dnl Check if $(CC) supports prototypes in function declarations and structures
  2319. -define(LOCAL_HAVE_PROTOTYPES,
  2320. -[AC_COMPILE_CHECK([function prototypes], ,
  2321. -[extern int test (int i, double x);],
  2322. -AC_DEFINE(HAVE_PROTOTYPES))
  2323. -AC_COMPILE_CHECK([function prototypes in structures], ,
  2324. -[struct s1 {int (*f) (int a);};
  2325. -struct s2 {int (*f) (double a);};],
  2326. -AC_DEFINE(HAVE_PROTOTYPES_IN_STRUCT))])dnl
  2327. -dnl
  2328. -AC_PROG_RANLIB
  2329. -AC_HAVE_HEADERS(memory.h)
  2330. -AC_STDC_HEADERS
  2331. -AC_HEADER_CHECK(complex.h, AC_DEFINE(HAVE_COMPLEX_H),)
  2332. -AC_HEADER_CHECK(malloc.h, AC_DEFINE(HAVE_MALLOC_H),)
  2333. -AC_HEADER_CHECK(varargs.h, AC_DEFINE(VARARGS),)
  2334. -AC_DEFINE(NOT_SEGMENTED)
  2335. -AC_SIZE_T
  2336. -AC_CONST
  2337. -AC_WORDS_BIGENDIAN
  2338. -AC_WITH(complex, AC_DEFINE(COMPLEX))
  2339. -AC_WITH(sparse, AC_DEFINE(SPARSE))
  2340. -AC_WITH(all, AC_DEFINE(COMPLEX))
  2341. -AC_WITH(all, AC_DEFINE(SPARSE))
  2342. -AC_WITH(unroll, AC_DEFINE(VUNROLL))
  2343. -AC_WITH(munroll, AC_DEFINE(MUNROLL))
  2344. -AC_WITH(segmem, AC_DEFINE(SEGMENTED))
  2345. -AC_WITH(float, AC_DEFINE(REAL_FLT))
  2346. -AC_WITH(double, AC_DEFINE(REAL_DBL))
  2347. -LIBS="$LIBS -lm"
  2348. -AC_COMPILE_CHECK([u_int],[#include <stdio.h>
  2349. -#ifdef __STDC__
  2350. -#include <stdlib.h>
  2351. -#endif],[u_int i; i = 1;],AC_DEFINE(U_INT_DEF))
  2352. -echo 'computing machine epsilon(s)'
  2353. -echo $CC -o macheps dmacheps.c
  2354. -$CC -o macheps dmacheps.c
  2355. -AC_DEFINE_UNQUOTED(D_MACHEPS,`macheps`)
  2356. -echo $CC -o macheps fmacheps.c
  2357. -$CC -o macheps fmacheps.c
  2358. -AC_DEFINE_UNQUOTED(F_MACHEPS,`macheps`)
  2359. -echo computing M_MAX_INT
  2360. -echo $CC -o maxint maxint.c
  2361. -$CC -o maxint maxint.c
  2362. -AC_DEFINE_UNQUOTED(M_MAX_INT,`maxint`)
  2363. -echo checking char '\\0' vs. float zeros
  2364. -AC_PROGRAM_EGREP(yes,[main() {
  2365. -    char    *cp = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
  2366. -    double    *dp;
  2367. -    dp = (double *)cp;
  2368. -    if ( *dp == 0.0 ) printf("yes\n");  }
  2369. -],AC_DEFINE(CHAR0ISDBL0))
  2370. -AC_HAVE_FUNCS(bcopy bzero)
  2371. -LOCAL_HAVE_PROTOTYPES
  2372. -AC_OUTPUT(makefile)
  2373. -echo "Extensions to basic version: use configure --with-opt1 --with-opt2"
  2374. -echo "  Option:"
  2375. -echo "    --with-complex     incorporate complex functions"
  2376. -echo "    --with-sparse      incorporate sparse matrix functions"
  2377. -echo "    --with-all         both of the above"
  2378. -echo "    --with-unroll      unroll low level loops on vectors"
  2379. -echo "    --with-munroll     unroll low level loops on matrices"
  2380. -echo "    --with-float       single precision"
  2381. -echo "    --with-double      double precision (default)"
  2382. -echo "Re-run configure with these options if you want them"
  2383. -# configure.in copyright (C) Brook Milligan and David Stewart, 1993
  2384. //GO.SYSIN DD configure.in
  2385. echo machine.h.in 1>&2
  2386. sed >machine.h.in <<'//GO.SYSIN DD machine.h.in' 's/^-//'
  2387. -/* Any machine specific stuff goes here */
  2388. -/* Add details necessary for your own installation here! */
  2389. -
  2390. -/* RCS id: $Id: machine.h.in,v 1.2 1994/03/13 23:07:30 des Exp $ */
  2391. -
  2392. -/* This is for use with "configure" -- if you are not using configure
  2393. -    then use machine.van for the "vanilla" version of machine.h */
  2394. -
  2395. -/* Note special macros: ANSI_C (ANSI C syntax)
  2396. -            SEGMENTED (segmented memory machine e.g. MS-DOS)
  2397. -            MALLOCDECL (declared if malloc() etc have
  2398. -                    been declared) */
  2399. -
  2400. -#undef const
  2401. -
  2402. -#undef MALLOCDECL
  2403. -#undef NOT_SEGMENTED
  2404. -#undef HAVE_MEMORY_H
  2405. -#undef HAVE_COMPLEX_H
  2406. -#undef HAVE_MALLOC_H
  2407. -#undef STDC_HEADERS
  2408. -#undef HAVE_BCOPY
  2409. -#undef HAVE_BZERO
  2410. -#undef CHAR0ISDBL0
  2411. -#undef WORDS_BIGENDIAN
  2412. -#undef U_INT_DEF
  2413. -#undef VARARGS
  2414. -#undef HAVE_PROTOTYPES
  2415. -#undef HAVE_PROTOTYPES_IN_STRUCT
  2416. -
  2417. -/* for inclusion into C++ files */
  2418. -#ifdef __cplusplus
  2419. -#define ANSI_C 1
  2420. -#ifndef HAVE_PROTOTYPES 
  2421. -#define HAVE_PROTOTYPES 1
  2422. -#endif
  2423. -#ifndef HAVE_PROTOTYPES_IN_STRUCT
  2424. -#define HAVE_PROTOTYPES_IN_STRUCT 1
  2425. -#endif
  2426. -#endif /* __cplusplus */
  2427. -
  2428. -/* example usage: VEC *PROTO(v_get,(int dim)); */
  2429. -#ifdef HAVE_PROTOTYPES
  2430. -#define    PROTO(name,args)    name args
  2431. -#else
  2432. -#define PROTO(name,args)    name()
  2433. -#endif /* HAVE_PROTOTYPES */
  2434. -#ifdef HAVE_PROTOTYPES_IN_STRUCT
  2435. -/* PROTO_() is to be used instead of PROTO() in struct's and typedef's */
  2436. -#define    PROTO_(name,args)    name args
  2437. -#else
  2438. -#define PROTO_(name,args)    name()
  2439. -#endif /* HAVE_PROTOTYPES_IN_STRUCT */
  2440. -
  2441. -/* for basic or larger versions */
  2442. -#undef COMPLEX
  2443. -#undef SPARSE
  2444. -
  2445. -/* for loop unrolling */
  2446. -#undef VUNROLL
  2447. -#undef MUNROLL
  2448. -
  2449. -/* for segmented memory */
  2450. -#ifndef NOT_SEGMENTED
  2451. -#define    SEGMENTED
  2452. -#endif
  2453. -
  2454. -/* if the system has malloc.h */
  2455. -#ifdef HAVE_MALLOC_H
  2456. -#define    MALLOCDECL    1
  2457. -#include    <malloc.h>
  2458. -#endif
  2459. -
  2460. -/* any compiler should have this header */
  2461. -/* if not, change it */
  2462. -#include        <stdio.h>
  2463. -
  2464. -
  2465. -/* Check for ANSI C memmove and memset */
  2466. -#ifdef STDC_HEADERS
  2467. -
  2468. -/* standard copy & zero functions */
  2469. -#define    MEM_COPY(from,to,size)    memmove((to),(from),(size))
  2470. -#define    MEM_ZERO(where,size)    memset((where),'\0',(size))
  2471. -
  2472. -#ifndef ANSI_C
  2473. -#define ANSI_C 1
  2474. -#endif
  2475. -
  2476. -#endif
  2477. -
  2478. -/* standard headers */
  2479. -#ifdef ANSI_C
  2480. -#include    <stdlib.h>
  2481. -#include    <stddef.h>
  2482. -#include    <string.h>
  2483. -#include    <float.h>
  2484. -#endif
  2485. -
  2486. -
  2487. -/* if have bcopy & bzero and no alternatives yet known, use them */
  2488. -#ifdef HAVE_BCOPY
  2489. -#ifndef MEM_COPY
  2490. -/* nonstandard copy function */
  2491. -#define    MEM_COPY(from,to,size)    bcopy((char *)(from),(char *)(to),(int)(size))
  2492. -#endif
  2493. -#endif
  2494. -
  2495. -#ifdef HAVE_BZERO
  2496. -#ifndef MEM_ZERO
  2497. -/* nonstandard zero function */
  2498. -#define    MEM_ZERO(where,size)    bzero((char *)(where),(int)(size))
  2499. -#endif
  2500. -#endif
  2501. -
  2502. -/* if the system has complex.h */
  2503. -#ifdef HAVE_COMPLEX_H
  2504. -#include    <complex.h>
  2505. -#endif
  2506. -
  2507. -/* If prototypes are available & ANSI_C not yet defined, then define it,
  2508. -    but don't include any header files as the proper ANSI C headers
  2509. -        aren't here */
  2510. -#ifdef HAVE_PROTOTYPES
  2511. -#ifndef ANSI_C
  2512. -#define ANSI_C  1
  2513. -#endif
  2514. -#endif
  2515. -
  2516. -/* floating point precision */
  2517. -
  2518. -/* you can choose single, double or long double (if available) precision */
  2519. -
  2520. -#define FLOAT         1
  2521. -#define DOUBLE         2
  2522. -#define LONG_DOUBLE     3
  2523. -
  2524. -#undef REAL_FLT
  2525. -#undef REAL_DBL
  2526. -
  2527. -/* if nothing is defined, choose double precision */
  2528. -#ifndef REAL_DBL
  2529. -#ifndef REAL_FLT
  2530. -#define REAL_DBL 1
  2531. -#endif
  2532. -#endif
  2533. -
  2534. -/* single precision */
  2535. -#ifdef REAL_FLT
  2536. -#define  Real float
  2537. -#define  LongReal float
  2538. -#define REAL FLOAT
  2539. -#define LONGREAL FLOAT
  2540. -#endif
  2541. -
  2542. -/* double precision */
  2543. -#ifdef REAL_DBL
  2544. -#define Real double
  2545. -#define LongReal double
  2546. -#define REAL DOUBLE
  2547. -#define LONGREAL DOUBLE
  2548. -#endif
  2549. -
  2550. -
  2551. -/* machine epsilon or unit roundoff error */
  2552. -/* This is correct on most IEEE Real precision systems */
  2553. -#ifdef DBL_EPSILON
  2554. -#if REAL == DOUBLE
  2555. -#define    MACHEPS    DBL_EPSILON
  2556. -#elif REAL == FLOAT
  2557. -#define    MACHEPS    FLT_EPSILON
  2558. -#elif REAL == LONGDOUBLE
  2559. -#define MACHEPS LDBL_EPSILON
  2560. -#endif
  2561. -#endif
  2562. -
  2563. -#undef F_MACHEPS
  2564. -#undef D_MACHEPS
  2565. -
  2566. -#ifndef MACHEPS
  2567. -#if REAL == DOUBLE
  2568. -#define    MACHEPS    D_MACHEPS
  2569. -#elif REAL == FLOAT  
  2570. -#define MACHEPS F_MACHEPS
  2571. -#elif REAL == LONGDOUBLE
  2572. -#define MACHEPS D_MACHEPS
  2573. -#endif
  2574. -#endif
  2575. -
  2576. -#undef M_MACHEPS
  2577. -
  2578. -/********************
  2579. -#ifdef DBL_EPSILON
  2580. -#define    MACHEPS    DBL_EPSILON
  2581. -#endif
  2582. -#ifdef M_MACHEPS
  2583. -#ifndef MACHEPS
  2584. -#define MACHEPS    M_MACHEPS
  2585. -#endif
  2586. -#endif
  2587. -********************/
  2588. -
  2589. -#undef    M_MAX_INT
  2590. -#ifdef    M_MAX_INT
  2591. -#ifndef MAX_RAND
  2592. -#define    MAX_RAND ((double)(M_MAX_INT))
  2593. -#endif
  2594. -#endif
  2595. -
  2596. -/* for non-ANSI systems */
  2597. -#ifndef HUGE_VAL
  2598. -#define HUGE_VAL HUGE
  2599. -#else
  2600. -#undef HUGE
  2601. -#define HUGE HUGE_VAL
  2602. -#endif
  2603. -
  2604. -
  2605. -#ifdef ANSI_C
  2606. -extern    int    isatty(int);
  2607. -#endif
  2608. -
  2609. //GO.SYSIN DD machine.h.in
  2610. echo copyright 1>&2
  2611. sed >copyright <<'//GO.SYSIN DD copyright' 's/^-//'
  2612. -
  2613. -/**************************************************************************
  2614. -**
  2615. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  2616. -**
  2617. -**                 Meschach Library
  2618. -** 
  2619. -** This Meschach Library is provided "as is" without any express 
  2620. -** or implied warranty of any kind with respect to this software. 
  2621. -** In particular the authors shall not be liable for any direct, 
  2622. -** indirect, special, incidental or consequential damages arising 
  2623. -** in any way from use of the software.
  2624. -** 
  2625. -** Everyone is granted permission to copy, modify and redistribute this
  2626. -** Meschach Library, provided:
  2627. -**  1.  All copies contain this copyright notice.
  2628. -**  2.  All modified copies shall carry a notice stating who
  2629. -**      made the last modification and the date of such modification.
  2630. -**  3.  No charge is made for this software or works derived from it.  
  2631. -**      This clause shall not be construed as constraining other software
  2632. -**      distributed on the same medium as this software, nor is a
  2633. -**      distribution fee considered a charge.
  2634. -**
  2635. -***************************************************************************/
  2636. -
  2637. //GO.SYSIN DD copyright
  2638. echo tutorial.c 1>&2
  2639. sed >tutorial.c <<'//GO.SYSIN DD tutorial.c' 's/^-//'
  2640. -
  2641. -/**************************************************************************
  2642. -**
  2643. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  2644. -**
  2645. -**                 Meschach Library
  2646. -** 
  2647. -** This Meschach Library is provided "as is" without any express 
  2648. -** or implied warranty of any kind with respect to this software. 
  2649. -** In particular the authors shall not be liable for any direct, 
  2650. -** indirect, special, incidental or consequential damages arising 
  2651. -** in any way from use of the software.
  2652. -** 
  2653. -** Everyone is granted permission to copy, modify and redistribute this
  2654. -** Meschach Library, provided:
  2655. -**  1.  All copies contain this copyright notice.
  2656. -**  2.  All modified copies shall carry a notice stating who
  2657. -**      made the last modification and the date of such modification.
  2658. -**  3.  No charge is made for this software or works derived from it.  
  2659. -**      This clause shall not be construed as constraining other software
  2660. -**      distributed on the same medium as this software, nor is a
  2661. -**      distribution fee considered a charge.
  2662. -**
  2663. -***************************************************************************/
  2664. -
  2665. -/* tutorial.c 10/12/1993 */
  2666. -
  2667. -/* routines from Chapter 1 of Meschach */
  2668. -
  2669. -static char rcsid[] = "$Id: tutorial.c,v 1.3 1994/01/16 22:53:09 des Exp $";
  2670. -
  2671. -#include "matrix.h"
  2672. -
  2673. -/* rk4 -- 4th order Runge--Kutta method */
  2674. -double rk4(f,t,x,h)
  2675. -double t, h;
  2676. -VEC    *(*f)(), *x;
  2677. -{
  2678. -   static VEC *v1=VNULL, *v2=VNULL, *v3=VNULL, *v4=VNULL;
  2679. -   static VEC *temp=VNULL;
  2680. -   
  2681. -   /* do not work with NULL initial vector */
  2682. -   if ( x == VNULL )
  2683. -     error(E_NULL,"rk4");
  2684. -
  2685. -   /* ensure that v1, ..., v4, temp are of the correct size */
  2686. -   v1   = v_resize(v1,x->dim);
  2687. -   v2   = v_resize(v2,x->dim);
  2688. -   v3   = v_resize(v3,x->dim);
  2689. -   v4   = v_resize(v4,x->dim);
  2690. -   temp = v_resize(temp,x->dim);
  2691. -
  2692. -   /* register workspace variables */
  2693. -   MEM_STAT_REG(v1,TYPE_VEC);
  2694. -   MEM_STAT_REG(v2,TYPE_VEC);
  2695. -   MEM_STAT_REG(v3,TYPE_VEC);
  2696. -   MEM_STAT_REG(v4,TYPE_VEC);
  2697. -   MEM_STAT_REG(temp,TYPE_VEC);
  2698. -   /* end of memory allocation */
  2699. -
  2700. -   (*f)(t,x,v1); /* most compilers allow: "f(t,x,v1);" */
  2701. -   v_mltadd(x,v1,0.5*h,temp);    /* temp = x+.5*h*v1 */
  2702. -   (*f)(t+0.5*h,temp,v2);
  2703. -   v_mltadd(x,v2,0.5*h,temp);    /* temp = x+.5*h*v2 */
  2704. -   (*f)(t+0.5*h,temp,v3);
  2705. -   v_mltadd(x,v3,h,temp);        /* temp = x+h*v3 */
  2706. -   (*f)(t+h,temp,v4);
  2707. -   
  2708. -   /* now add: v1+2*v2+2*v3+v4 */
  2709. -   v_copy(v1,temp);              /* temp = v1 */
  2710. -   v_mltadd(temp,v2,2.0,temp);   /* temp = v1+2*v2 */
  2711. -   v_mltadd(temp,v3,2.0,temp);   /* temp = v1+2*v2+2*v3 */
  2712. -   v_add(temp,v4,temp);          /* temp = v1+2*v2+2*v3+v4 */
  2713. -   
  2714. -   /* adjust x */
  2715. -   v_mltadd(x,temp,h/6.0,x);     /* x = x+(h/6)*temp */
  2716. -   
  2717. -   return t+h;                   /* return the new time */
  2718. -}
  2719. -
  2720. -
  2721. -
  2722. -/* rk4 -- 4th order Runge-Kutta method */
  2723. -/* another variant */
  2724. -double rk4_var(f,t,x,h)
  2725. -double t, h;
  2726. -VEC    *(*f)(), *x;
  2727. -{
  2728. -   static VEC *v1, *v2, *v3, *v4, *temp;
  2729. -   
  2730. -   /* do not work with NULL initial vector */
  2731. -   if ( x == VNULL )        error(E_NULL,"rk4");
  2732. -   
  2733. -   /* ensure that v1, ..., v4, temp are of the correct size */
  2734. -   v_resize_vars(x->dim, &v1, &v2, &v3, &v4, &temp, NULL);
  2735. -
  2736. -   /* register workspace variables */
  2737. -   mem_stat_reg_vars(0, TYPE_VEC, &v1, &v2, &v3, &v4, &temp, NULL);
  2738. -   /* end of memory allocation */
  2739. -
  2740. -   (*f)(t,x,v1);             v_mltadd(x,v1,0.5*h,temp);
  2741. -   (*f)(t+0.5*h,temp,v2);    v_mltadd(x,v2,0.5*h,temp);
  2742. -   (*f)(t+0.5*h,temp,v3);    v_mltadd(x,v3,h,temp);
  2743. -   (*f)(t+h,temp,v4);
  2744. -   
  2745. -   /* now add: temp = v1+2*v2+2*v3+v4 */
  2746. -   v_linlist(temp, v1, 1.0, v2, 2.0, v3, 2.0, v4, 1.0, VNULL);
  2747. -   /* adjust x */
  2748. -   v_mltadd(x,temp,h/6.0,x);     /* x = x+(h/6)*temp */
  2749. -   
  2750. -   return t+h;                   /* return the new time */
  2751. -}
  2752. -
  2753. -
  2754. -/* f -- right-hand side of ODE solver */
  2755. -VEC    *f(t,x,out)
  2756. -VEC    *x, *out;
  2757. -double    t;
  2758. -{
  2759. -   if ( x == VNULL || out == VNULL )
  2760. -     error(E_NULL,"f");
  2761. -   if ( x->dim != 2 || out->dim != 2 )
  2762. -     error(E_SIZES,"f");
  2763. -   
  2764. -   out->ve[0] = x->ve[1];
  2765. -   out->ve[1] = - x->ve[0];
  2766. -   
  2767. -   return out;
  2768. -}
  2769. -
  2770. -
  2771. -void tutor_rk4()
  2772. -{
  2773. -   VEC        *x;
  2774. -   VEC        *f();
  2775. -   double     h, t, t_fin;
  2776. -   double     rk4();
  2777. -   
  2778. -   input("Input initial time: ","%lf",&t);
  2779. -   input("Input final time: ",  "%lf",&t_fin);
  2780. -   x = v_get(2);    /* this is the size needed by f() */
  2781. -   prompter("Input initial state:\n");    x = v_input(VNULL);
  2782. -   input("Input step size: ",   "%lf",&h);
  2783. -   
  2784. -   printf("# At time %g, the state is\n",t);
  2785. -   v_output(x);
  2786. -   while (t < t_fin)
  2787. -   {
  2788. -      /* you can use t = rk4_var(f,t,x,min(h,t_fin-t)); */
  2789. -      t = rk4(f,t,x,min(h,t_fin-t));   /* new t is returned */
  2790. -      printf("# At time %g, the state is\n",t);
  2791. -      v_output(x);
  2792. -   }
  2793. -}
  2794. -
  2795. -
  2796. -
  2797. -
  2798. -#include "matrix2.h"
  2799. -
  2800. -void tutor_ls()
  2801. -{
  2802. -   MAT *A, *QR;
  2803. -   VEC *b, *x, *diag;
  2804. -   
  2805. -   /* read in A matrix */
  2806. -   printf("Input A matrix:\n");
  2807. -   
  2808. -   A = m_input(MNULL);     /* A has whatever size is input */
  2809. -   
  2810. -   if ( A->m < A->n )
  2811. -   {
  2812. -      printf("Need m >= n to obtain least squares fit\n");
  2813. -      exit(0);
  2814. -   }
  2815. -   printf("# A =\n");       m_output(A);
  2816. -   diag = v_get(A->m);
  2817. -   /* QR is to be the QR factorisation of A */
  2818. -   QR = m_copy(A,MNULL);
  2819. -   QRfactor(QR,diag);   
  2820. -   /* read in b vector */
  2821. -   printf("Input b vector:\n");
  2822. -   b = v_get(A->m);
  2823. -   b = v_input(b);
  2824. -   printf("# b =\n");       v_output(b);
  2825. -   
  2826. -   /* solve for x */
  2827. -   x = QRsolve(QR,diag,b,VNULL);
  2828. -   printf("Vector of best fit parameters is\n");
  2829. -   v_output(x);
  2830. -   /* ... and work out norm of errors... */
  2831. -   printf("||A*x-b|| = %g\n",
  2832. -      v_norm2(v_sub(mv_mlt(A,x,VNULL),b,VNULL)));
  2833. -}
  2834. -
  2835. -
  2836. -#include <math.h>
  2837. -#include "iter.h"
  2838. -
  2839. -
  2840. -#define N 50
  2841. -#define VEC2MAT(v,m)  vm_move((v),0,(m),0,0,N,N);
  2842. -
  2843. -#define PI 3.141592653589793116
  2844. -#define index(i,j) (N*((i)-1)+(j)-1)
  2845. -
  2846. -/* right hand side function (for generating b) */
  2847. -double f1(x,y)
  2848. -double x,y;
  2849. -{
  2850. -  /* return 2.0*PI*PI*sin(PI*x)*sin(PI*y); */
  2851. -   return exp(x*y);
  2852. -}
  2853. -
  2854. -/* discrete laplacian */
  2855. -SPMAT *laplacian(A)
  2856. -SPMAT *A;
  2857. -{
  2858. -   Real h;
  2859. -   int i,j;
  2860. -   
  2861. -   if (!A)
  2862. -     A = sp_get(N*N,N*N,5);
  2863. -
  2864. -   for ( i = 1; i <= N; i++ )
  2865. -     for ( j = 1; j <= N; j++ )
  2866. -     {
  2867. -        if ( i < N )
  2868. -      sp_set_val(A,index(i,j),index(i+1,j),-1.0);
  2869. -        if ( i > 1 )
  2870. -      sp_set_val(A,index(i,j),index(i-1,j),-1.0);
  2871. -        if ( j < N )
  2872. -      sp_set_val(A,index(i,j),index(i,j+1),-1.0);
  2873. -        if ( j > 1 )
  2874. -      sp_set_val(A,index(i,j),index(i,j-1),-1.0);
  2875. -        sp_set_val(A,index(i,j),index(i,j),4.0);
  2876. -     }
  2877. -   return A;
  2878. -}
  2879. -
  2880. -/* generating right hand side */
  2881. -VEC *rhs_lap(b)
  2882. -VEC *b;
  2883. -{
  2884. -   Real h,h2,x,y;
  2885. -   int i,j;
  2886. -   
  2887. -   if (!b)
  2888. -     b = v_get(N*N);
  2889. -
  2890. -   h = 1.0/(N+1);      /* for a unit square */
  2891. -   h2 = h*h;
  2892. -   x = 0.0;
  2893. -   for ( i = 1; i <= N; i++ ) {
  2894. -      x += h;
  2895. -      y = 0.0;
  2896. -     for ( j = 1; j <= N; j++ ) {
  2897. -    y += h;
  2898. -    b->ve[index(i,j)] = h2*f1(x,y);
  2899. -     }
  2900. -   }
  2901. -   return b;
  2902. -}
  2903. -   
  2904. -void tut_lap()
  2905. -{
  2906. -   SPMAT *A, *LLT;
  2907. -   VEC *b, *out, *x;
  2908. -   MAT *B;
  2909. -   int num_steps;
  2910. -   FILE *fp;
  2911. -
  2912. -   A = sp_get(N*N,N*N,5);
  2913. -   b = v_get(N*N);
  2914. -
  2915. -   laplacian(A);
  2916. -   LLT = sp_copy(A);
  2917. -   spICHfactor(LLT);
  2918. -
  2919. -   out = v_get(A->m);
  2920. -   x = v_get(A->m);
  2921. -
  2922. -   rhs_lap(b);   /* new rhs */
  2923. -   iter_spcg(A,LLT,b,1e-6,out,1000,&num_steps);
  2924. -   printf("Number of iterations = %d\n",num_steps);
  2925. -
  2926. -   /* save b as a MATLAB matrix */
  2927. -
  2928. -   fp = fopen("laplace.mat","w");  /* b will be saved in laplace.mat */
  2929. -   if (fp == NULL) {
  2930. -      printf("Cannot open %s\n","laplace.mat");
  2931. -      exit(1);
  2932. -   }
  2933. -   
  2934. -   /* b must be transformed to a matrix */
  2935. -   
  2936. -   B = m_get(N,N);
  2937. -   VEC2MAT(out,B);
  2938. -   m_save(fp,B,"sol");  /* sol is an internal name in MATLAB */
  2939. -
  2940. -}
  2941. -
  2942. -
  2943. -void main()
  2944. -{
  2945. -   int i;
  2946. -
  2947. -   input("Choose the problem (1=Runge-Kutta, 2=least squares,3=laplace): ",
  2948. -     "%d",&i);
  2949. -   switch (i) {
  2950. -    case 1: tutor_rk4(); break;
  2951. -    case 2: tutor_ls(); break;
  2952. -    case 3: tut_lap(); break;
  2953. -    default: 
  2954. -      printf(" Wrong value of i (only 1, 2 or 3)\n\n");
  2955. -      break;
  2956. -   }
  2957. -
  2958. -}
  2959. -
  2960. //GO.SYSIN DD tutorial.c
  2961. echo tutadv.c 1>&2
  2962. sed >tutadv.c <<'//GO.SYSIN DD tutadv.c' 's/^-//'
  2963. -
  2964. -/* routines from the section 8 of tutorial.txt */
  2965. -
  2966. -#include "matrix.h"
  2967. -
  2968. -#define M3D_LIST    3      /* list number */
  2969. -#define TYPE_MAT3D  0      /* the number of a type */
  2970. -
  2971. -/* type for 3 dimensional matrices */
  2972. -typedef struct {
  2973. -    int l,m,n;    /* actual dimensions */
  2974. -    int max_l, max_m, max_n;    /* maximal dimensions */
  2975. -    Real ***me;    /* pointer to matrix elements */
  2976. -                   /* we do not consider segmented memory */
  2977. -        Real *base, **me2d;  /* me and me2d are additional pointers 
  2978. -                to base */
  2979. -} MAT3D;
  2980. -
  2981. -
  2982. -/* function for creating a variable of MAT3D type */
  2983. -
  2984. -MAT3D *m3d_get(l,m,n)
  2985. -int l,m,n;
  2986. -{
  2987. -  MAT3D *mat;
  2988. -  int i,j,k;
  2989. -
  2990. -  /* check if arguments are positive */
  2991. -  if (l <= 0 || m <= 0 || n <= 0)
  2992. -    error(E_NEG,"m3d_get");
  2993. -
  2994. -    /* new structure */
  2995. -  if ((mat = NEW(MAT3D)) == (MAT3D *)NULL)
  2996. -    error(E_MEM,"m3d_get");
  2997. -  else if (mem_info_is_on()) {
  2998. -    /* record how many bytes is allocated */
  2999. -    mem_bytes_list(TYPE_MAT3D,0,sizeof(MAT3D),M3D_LIST);
  3000. -    /* record a new allocated variable */
  3001. -    mem_numvar_list(TYPE_MAT3D,1,M3D_LIST);
  3002. -  }
  3003. -
  3004. -  mat->l = mat->max_l = l;
  3005. -  mat->m = mat->max_m = m;
  3006. -  mat->n = mat->max_n = n;
  3007. -
  3008. -    /* allocate memory for 3D array */
  3009. -  if ((mat->base = NEW_A(l*m*n,Real)) == (Real *)NULL) 
  3010. -    error(E_MEM,"m3d_get");
  3011. -  else if (mem_info_is_on())
  3012. -    mem_bytes_list(TYPE_MAT3D,0,l*m*n*sizeof(Real),M3D_LIST);
  3013. -
  3014. -    /* allocate memory for 2D pointers */
  3015. -  if ((mat->me2d = NEW_A(l*m,Real *)) == (Real **)NULL)
  3016. -    error(E_MEM,"m3d_get");
  3017. -  else if (mem_info_is_on())
  3018. -    mem_bytes_list(TYPE_MAT3D,0,l*m*sizeof(Real *),M3D_LIST);      
  3019. -
  3020. -    /* allocate  memory for 1D pointers */
  3021. -  if ((mat->me = NEW_A(l,Real **)) == (Real ***)NULL)
  3022. -    error(E_MEM,"m3d_get");
  3023. -  else if (mem_info_is_on())
  3024. -    mem_bytes_list(TYPE_MAT3D,0,l*sizeof(Real **),M3D_LIST);
  3025. -
  3026. -      /* pointers to 2D matrices */
  3027. -  for (i=0,k=0; i < l; i++)
  3028. -    for (j=0; j < m; j++)
  3029. -      mat->me2d[k++] = &mat->base[(i*m+j)*n];
  3030. -
  3031. -       /* pointers to rows */
  3032. -  for (i=0; i < l; i++)
  3033. -    mat->me[i] = &mat->me2d[i*m];
  3034. -
  3035. -  return mat;
  3036. -}
  3037. -
  3038. -
  3039. -/* deallocate a variable of type MAT3D */
  3040. -
  3041. -int m3d_free(mat)
  3042. -MAT3D *mat;
  3043. -{
  3044. -       /* do not try to deallocate the NULL pointer */
  3045. -  if (mat == (MAT3D *)NULL)
  3046. -    return -1;
  3047. -    
  3048. -      /* first deallocate base */
  3049. -  if (mat->base != (Real *)NULL) {
  3050. -    if (mem_info_is_on())
  3051. -    /* record how many bytes is deallocated */
  3052. -      mem_bytes_list(TYPE_MAT3D,mat->max_l*mat->max_m*mat->max_n*sizeof(Real),
  3053. -             0,M3D_LIST);
  3054. -    free((char *)mat->base);
  3055. -  }
  3056. -
  3057. -     /* deallocate array of 2D pointers */
  3058. -  if (mat->me2d != (Real **)NULL) {
  3059. -    if (mem_info_is_on())
  3060. -    /* record how many bytes is deallocated */
  3061. -      mem_bytes_list(TYPE_MAT3D,mat->max_l*mat->max_m*sizeof(Real *),
  3062. -             0,M3D_LIST);
  3063. -    free((char *)mat->me2d);
  3064. -  }
  3065. -
  3066. -     /* deallocate array of 1D pointers */
  3067. -  if (mat->me != (Real ***)NULL) {
  3068. -    if (mem_info_is_on())
  3069. -    /* record how many bytes is deallocated */
  3070. -      mem_bytes_list(TYPE_MAT3D,mat->max_l*sizeof(Real **),0,M3D_LIST);
  3071. -    free((char *)mat->me);
  3072. -  }
  3073. -
  3074. -    /* deallocate  MAT3D structure */
  3075. -  if (mem_info_is_on()) {
  3076. -    mem_bytes_list(TYPE_MAT3D,sizeof(MAT3D),0,M3D_LIST);
  3077. -    mem_numvar_list(TYPE_MAT3D,-1,M3D_LIST);
  3078. -  }
  3079. -  free((char *)mat);
  3080. -
  3081. -  return 0;
  3082. -}
  3083. -
  3084. -/*=============================================*/
  3085. -
  3086. -char *m3d_names[] = {
  3087. -  "MAT3D"
  3088. -};
  3089. -
  3090. -
  3091. -#define M3D_NUM  (sizeof(m3d_names)/sizeof(*m3d_names))
  3092. -
  3093. -int (*m3d_free_funcs[M3D_NUM])() = {
  3094. -  m3d_free
  3095. -};
  3096. -
  3097. -static MEM_ARRAY m3d_sum[M3D_NUM];
  3098. -
  3099. -
  3100. -/* test routing for allocating/deallocating static variables */
  3101. -void test_stat(k)
  3102. -int k;
  3103. -{
  3104. -   static MAT3D *work;
  3105. -
  3106. -   if (!work) {
  3107. -      work = m3d_get(10,10,10);
  3108. -      mem_stat_reg_list(&work,TYPE_MAT3D,M3D_LIST);
  3109. -      work->me[9][9][9] = -3.14;
  3110. -   }
  3111. -   
  3112. -   if (k == 9) 
  3113. -     printf(" work[9][9][9] = %g\n",work->me[9][9][9]);
  3114. -}
  3115. -
  3116. -
  3117. -void main()
  3118. -{
  3119. -  MAT3D *M;
  3120. -  int i,j,k;
  3121. -
  3122. -  mem_info_on(TRUE);
  3123. -  /* can be the first command */
  3124. -  mem_attach_list(M3D_LIST,M3D_NUM,m3d_names,m3d_free_funcs,m3d_sum);
  3125. -
  3126. -  M = m3d_get(3,4,5);
  3127. -  mem_info_file(stdout,M3D_LIST);
  3128. -
  3129. -  /* make use of M->me[i][j][k], where i,j,k are non-negative and 
  3130. -    i < 3, j < 4, k < 5 */
  3131. -
  3132. -  mem_stat_mark(1);
  3133. -  for (i=0; i < 3; i++)
  3134. -    for (j=0; j < 4; j++)
  3135. -      for (k=0; k < 5; k++) {
  3136. -     test_stat(i+j+k);
  3137. -     M->me[i][j][k] = i+j+k;
  3138. -      }
  3139. -  mem_stat_free_list(1,M3D_LIST);
  3140. -  mem_info_file(stdout,M3D_LIST);
  3141. -
  3142. -  printf(" M[%d][%d][%d] = %g\n",2,3,4,M->me[2][3][4]);
  3143. -
  3144. -  mem_stat_mark(2);
  3145. -  test_stat(9);
  3146. -  mem_stat_free_list(2,M3D_LIST);
  3147. -
  3148. -  m3d_free(M);  /* if M is not necessary */
  3149. -  mem_info_file(stdout,M3D_LIST);
  3150. -
  3151. -}
  3152. -
  3153. -
  3154. -
  3155. //GO.SYSIN DD tutadv.c
  3156. echo rk4.dat 1>&2
  3157. sed >rk4.dat <<'//GO.SYSIN DD rk4.dat' 's/^-//'
  3158. -# No. of a problem
  3159. -1
  3160. -# Initial time
  3161. -0
  3162. -# Final time
  3163. -1
  3164. -# Solution is x(t) = (cos(t),-sin(t))
  3165. -# x(0) =
  3166. -Vector: dim: 2
  3167. -1       0
  3168. -# Step size
  3169. -0.1
  3170. //GO.SYSIN DD rk4.dat
  3171. echo ls.dat 1>&2
  3172. sed >ls.dat <<'//GO.SYSIN DD ls.dat' 's/^-//'
  3173. -# No. of a problem
  3174. -2
  3175. -# A = 
  3176. -Matrix: 5 by 3
  3177. -row 0:              3             -1              2 
  3178. -row 1:              2             -1            1.2 
  3179. -row 2:            2.5              1           -1.5 
  3180. -row 3:              3              1              1 
  3181. -row 4:             -1              1           -2.2 
  3182. -
  3183. -# b =
  3184. -Vector: dim: 5
  3185. -           5            3            2            4            6 
  3186. -
  3187. //GO.SYSIN DD ls.dat
  3188. echo makefile 1>&2
  3189. sed >makefile <<'//GO.SYSIN DD makefile' 's/^-//'
  3190. -# Generated automatically from makefile.in by configure.
  3191. -#
  3192. -# Makefile for Meschach via autoconf
  3193. -#
  3194. -# Copyright (C) David Stewart & Zbigniew Leyk 1993
  3195. -#
  3196. -# $Id: $
  3197. -#
  3198. -
  3199. -srcdir = .
  3200. -VPATH = .
  3201. -
  3202. -CC = cc
  3203. -
  3204. -DEFS = -DHAVE_CONFIG_H
  3205. -LIBS =  -lm
  3206. -RANLIB = ranlib
  3207. -
  3208. -
  3209. -CFLAGS = -O
  3210. -
  3211. -
  3212. -.c.o:
  3213. -    $(CC) -c $(CFLAGS) $(DEFS) $<
  3214. -
  3215. -SHELL = /bin/sh
  3216. -MES_PAK = mesch12b
  3217. -TAR = tar
  3218. -SHAR = stree -u
  3219. -ZIP = zip -r -l
  3220. -FLIST = FILELIST
  3221. -
  3222. -###############################
  3223. -
  3224. -LIST1 = copy.o err.o matrixio.o memory.o vecop.o matop.o pxop.o \
  3225. -    submat.o init.o otherio.o machine.o matlab.o ivecop.o version.o \
  3226. -    meminfo.o memstat.o
  3227. -LIST2 = lufactor.o bkpfacto.o chfactor.o qrfactor.o solve.o hsehldr.o \
  3228. -    givens.o update.o norm.o hessen.o symmeig.o schur.o svd.o fft.o \
  3229. -    mfunc.o bdfactor.o
  3230. -LIST3 = sparse.o sprow.o sparseio.o spchfctr.o splufctr.o \
  3231. -    spbkp.o spswap.o iter0.o itersym.o iternsym.o
  3232. -ZLIST1 = zmachine.o zcopy.o zmatio.o zmemory.o zvecop.o zmatop.o znorm.o \
  3233. -     zfunc.o 
  3234. -ZLIST2 = zlufctr.o zsolve.o zmatlab.o zhsehldr.o zqrfctr.o \
  3235. -         zgivens.o  zhessen.o zschur.o
  3236. -
  3237. -# they are no longer supported
  3238. -# if you use them add oldpart to all and sparse
  3239. -OLDLIST = conjgrad.o lanczos.o arnoldi.o
  3240. -
  3241. -ALL_LISTS = $(LIST1) $(LIST2) $(LIST3) $(ZLIST1) $(ZLIST2) $(OLDLIST)
  3242. -
  3243. -HBASE = err.h meminfo.h machine.h matrix.h
  3244. -
  3245. -HLIST = $(HBASE) iter.h matlab.h matrix2.h  oldnames.h sparse.h \
  3246. -    sparse2.h  zmatrix.h zmatrix2.h
  3247. -
  3248. -TORTURE = torture.o sptort.o ztorture.o memtort.o itertort.o \
  3249. -     mfuntort.o iotort.o
  3250. -
  3251. -OTHERS = dmacheps.c extras.c fmacheps.c maxint.c  makefile.in \
  3252. -     README configure configure.in machine.h.in copyright \
  3253. -     tutorial.c tutadv.c rk4.dat ls.dat makefile $(FLIST)
  3254. -
  3255. -
  3256. -# Different configurations
  3257. -# the dependencies **between** the parts are for dmake
  3258. -all:  part1 part2 part3 zpart1 zpart2 
  3259. -part2: part1
  3260. -part3: part2
  3261. -basic: part1 part2
  3262. -sparse: part1 part2 part3 
  3263. -zpart2: zpart1
  3264. -complex: part1 part2 zpart1 zpart2
  3265. -
  3266. -
  3267. -$(LIST1): $(HBASE)
  3268. -part1: $(LIST1)
  3269. -    ar ru meschach.a $(LIST1); $(RANLIB) meschach.a
  3270. -
  3271. -$(LIST2): $(HBASE) matrix2.h
  3272. -part2: $(LIST2)
  3273. -    ar ru meschach.a $(LIST2); $(RANLIB) meschach.a
  3274. -
  3275. -$(LIST3): $(HBASE) sparse.h sparse2.h
  3276. -part3: $(LIST3)
  3277. -    ar ru meschach.a $(LIST3); $(RANLIB) meschach.a
  3278. -
  3279. -$(ZLIST1): $(HBASDE) zmatrix.h
  3280. -zpart1: $(ZLIST1)
  3281. -    ar ru meschach.a $(ZLIST1); $(RANLIB) meschach.a
  3282. -
  3283. -$(ZLIST2): $(HBASE) zmatrix.h zmatrix2.h 
  3284. -zpart2: $(ZLIST2)
  3285. -    ar ru meschach.a $(ZLIST2); $(RANLIB) meschach.a
  3286. -
  3287. -$(OLDLIST): $(HBASE) sparse.h sparse2.h 
  3288. -oldpart: $(OLDLIST)
  3289. -    ar ru meschach.a $(OLDLIST); $(RANLIB) meschach.a
  3290. -
  3291. -
  3292. -
  3293. -#######################################
  3294. -
  3295. -tar:
  3296. -    - /bin/rm -f $(MES_PAK).tar
  3297. -    chmod 644 `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  3298. -    $(OTHERS) $(HLIST)  `echo $(TORTURE) | sed -e 's/\.o/.c/g'` 
  3299. -    chmod 755 configure
  3300. -    $(MAKE) list
  3301. -    $(TAR) cvf $(MES_PAK).tar \
  3302. -     `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  3303. -    $(HLIST)  $(OTHERS) \
  3304. -    `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  3305. -    MACHINES DOC
  3306. -
  3307. -# use this only for PC machines    
  3308. -msdos-zip:
  3309. -    - /bin/rm -f $(MES_PAK).zip
  3310. -    chmod 644 `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  3311. -    $(OTHERS) $(HLIST) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` 
  3312. -    chmod 755 configure
  3313. -    $(MAKE) list
  3314. -    $(ZIP)  $(MES_PAK).zip \
  3315. -     `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  3316. -    $(HLIST)  $(OTHERS) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  3317. -    MACHINES DOC
  3318. -    
  3319. -
  3320. -fullshar:
  3321. -    - /bin/rm -f $(MES_PAK).shar;
  3322. -    chmod 644 `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  3323. -    $(OTHERS) $(HLIST) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` 
  3324. -    chmod 755 configure
  3325. -    $(MAKE) list
  3326. -    $(SHAR) `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  3327. -    $(HLIST)  $(OTHERS) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  3328. -    MACHINES DOC > $(MES_PAK).shar
  3329. -
  3330. -shar:
  3331. -    - /bin/rm -f meschach1.shar meschach2.shar meschach3.shar \
  3332. -    meschach4.shar oldmeschach.shar meschach0.shar 
  3333. -    chmod 644 `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  3334. -    $(OTHERS) $(HLIST) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` 
  3335. -    chmod 755 configure    
  3336. -    $(MAKE) list
  3337. -    $(SHAR) `echo $(LIST1) | sed -e 's/\.o/.c/g'` > meschach1.shar
  3338. -    $(SHAR) `echo $(LIST2) | sed -e 's/\.o/.c/g'` > meschach2.shar
  3339. -    $(SHAR) `echo $(LIST3) | sed -e 's/\.o/.c/g'` > meschach3.shar    
  3340. -    $(SHAR) `echo $(ZLIST1) | sed -e 's/\.o/.c/g'` \
  3341. -      `echo $(ZLIST2) | sed -e 's/\.o/.c/g'` > meschach4.shar
  3342. -    $(SHAR) `echo $(OLDLIST) | sed -e 's/\.o/.c/g'` > oldmeschach.shar
  3343. -    $(SHAR) $(OTHERS) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  3344. -      $(HLIST)  DOC MACHINES  > meschach0.shar
  3345. -
  3346. -list:
  3347. -    /bin/rm -f $(FLIST)
  3348. -    ls -lR `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  3349. -    `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  3350. -    $(HLIST) $(OTHERS) MACHINES DOC \
  3351. -    |awk '/^$$/ {print};/^[-d]/ {printf("%s %s   %10d %s %s %s %s\n", \
  3352. -     $$1,$$2,$$5,$$6,$$7,$$8,$$9)}; /^[^-d]/ {print}' \
  3353. -    > $(FLIST)
  3354. -
  3355. -
  3356. -
  3357. -clean:
  3358. -    /bin/rm -f *.o core asx5213a.mat iotort.dat 
  3359. -
  3360. -cleanup:
  3361. -    /bin/rm -f *.o core asx5213a.mat iotort.dat *.a 
  3362. -
  3363. -realclean:
  3364. -    /bin/rm -f *.o core asx5213a.mat iotort.dat *.a
  3365. -    /bin/rm -f torture sptort ztorture memtort itertort mfuntort iotort
  3366. -    /bin/rm -f makefile machine.h config.status maxint macheps
  3367. -alltorture: torture sptort ztorture memtort itertort mfuntort iotort
  3368. -
  3369. -torture:torture.o meschach.a
  3370. -    $(CC) $(CFLAGS) $(DEFS) -o torture torture.o \
  3371. -    meschach.a $(LIBS)
  3372. -sptort:sptort.o meschach.a
  3373. -    $(CC) $(CFLAGS) $(DEFS) -o sptort sptort.o \
  3374. -    meschach.a $(LIBS)
  3375. -memtort: memtort.o meschach.a
  3376. -    $(CC) $(CFLAGS) $(DEFS) -o memtort memtort.o \
  3377. -    meschach.a $(LIBS)
  3378. -ztorture:ztorture.o meschach.a
  3379. -    $(CC) $(CFLAGS) $(DEFS) -o ztorture ztorture.o \
  3380. -    meschach.a $(LIBS)
  3381. -itertort: itertort.o meschach.a
  3382. -    $(CC) $(CFLAGS) $(DEFS) -o itertort itertort.o \
  3383. -    meschach.a $(LIBS)
  3384. -
  3385. -iotort: iotort.o meschach.a
  3386. -    $(CC) $(CFLAGS) $(DEFS) -o iotort iotort.o \
  3387. -    meschach.a $(LIBS)
  3388. -mfuntort: mfuntort.o meschach.a
  3389. -    $(CC) $(CFLAGS) $(DEFS) -o mfuntort mfuntort.o \
  3390. -    meschach.a $(LIBS)
  3391. -tstmove: tstmove.o meschach.a
  3392. -    $(CC) $(CFLAGS) $(DEFS) -o tstmove tstmove.o \
  3393. -    meschach.a $(LIBS)
  3394. -tstpxvec: tstpxvec.o meschach.a
  3395. -    $(CC) $(CFLAGS) $(DEFS) -o tstpxvec tstpxvec.o \
  3396. -    meschach.a $(LIBS)
  3397. -
  3398. //GO.SYSIN DD makefile
  3399. echo FILELIST 1>&2
  3400. sed >FILELIST <<'//GO.SYSIN DD FILELIST' 's/^-//'
  3401. --rw-r----- 1            0 May 18 11:56 FILELIST
  3402. --rw-r--r-- 1        18006 Apr 06 11:56 README
  3403. --rw-r--r-- 1         4844 Jan 13 16:45 arnoldi.c
  3404. --rw-r--r-- 1        13380 May 18 09:20 bdfactor.c
  3405. --rw-r--r-- 1         8450 Jan 13 16:45 bkpfacto.c
  3406. --rw-r--r-- 1         5022 Jan 13 16:36 chfactor.c
  3407. --rwxr-xr-x 1        26888 Mar 08 14:54 configure
  3408. --rw-r--r-- 1         3536 Mar 08 15:42 configure.in
  3409. --rw-r--r-- 1         8250 Jan 13 16:36 conjgrad.c
  3410. --rw-r--r-- 1         5530 Jan 13 16:37 copy.c
  3411. --rw-r--r-- 1         1124 Jan 13 16:54 copyright
  3412. --rw-r--r-- 1         1402 Jan 13 16:37 dmacheps.c
  3413. --rw-r--r-- 1         9756 Jan 13 16:38 err.c
  3414. --rw-r--r-- 1         5678 Jan 13 16:38 err.h
  3415. --rw-r--r-- 1        10923 Jan 13 16:45 extras.c
  3416. --rw-r--r-- 1         3892 Jan 13 16:45 fft.c
  3417. --rw-r--r-- 1         1400 Jan 13 16:39 fmacheps.c
  3418. --rw-r--r-- 1         3603 Jan 13 16:39 givens.c
  3419. --rw-r--r-- 1         4063 Jan 13 16:36 hessen.c
  3420. --rw-r--r-- 1         4735 Jan 13 16:36 hsehldr.c
  3421. --rw-r--r-- 1         5889 Jan 13 16:37 init.c
  3422. --rw-r--r-- 1         3396 Jan 14 11:46 iotort.c
  3423. --rw-r--r-- 1         6911 Mar 08 15:49 iter.h
  3424. --rw-r--r-- 1         8878 Jan 13 16:38 iter0.c
  3425. --rw-r--r-- 1        30104 Feb 02 17:03 iternsym.c
  3426. --rw-r--r-- 1        13826 Jan 13 16:39 itersym.c
  3427. --rw-r--r-- 1        16178 Jan 14 11:46 itertort.c
  3428. --rw-r--r-- 1         9800 Jan 13 16:45 ivecop.c
  3429. --rw-r--r-- 1         7733 Jan 13 16:28 lanczos.c
  3430. --rw-r--r-- 1          397 Jan 13 16:49 ls.dat
  3431. --rw-r--r-- 1         6594 Mar 14 09:09 lufactor.c
  3432. --rw-r--r-- 1         3669 Jan 25 09:39 machine.c
  3433. --rw-r--r-- 1         4526 Mar 08 14:55 machine.h
  3434. --rw-r--r-- 1         4429 Mar 14 09:08 machine.h.in
  3435. --rw-r--r-- 1         5891 Mar 14 11:23 makefile
  3436. --rw-r--r-- 1         5898 Mar 14 11:24 makefile.in
  3437. --rw-r--r-- 1         5063 Jan 13 16:30 matlab.c
  3438. --rw-r--r-- 1         2998 Jan 13 16:45 matlab.h
  3439. --rw-r--r-- 1        12014 Jan 13 16:30 matop.c
  3440. --rw-r--r-- 1        19232 Apr 16 10:35 matrix.h
  3441. --rw-r--r-- 1         8291 Jan 13 16:31 matrix2.h
  3442. --rw-r--r-- 1        13409 Jan 13 16:31 matrixio.c
  3443. --rw-r--r-- 1         1257 Jan 13 16:31 maxint.c
  3444. --rw-r--r-- 1         9155 Jan 13 16:32 meminfo.c
  3445. --rw-r--r-- 1         4148 Jan 13 16:32 meminfo.h
  3446. --rw-r--r-- 1        19918 Apr 05 12:13 memory.c
  3447. --rw-r--r-- 1         8644 Jan 13 16:33 memstat.c
  3448. --rw-r--r-- 1        17345 Jan 14 11:46 memtort.c
  3449. --rw-r--r-- 1         9018 Jan 13 16:34 mfunc.c
  3450. --rw-r--r-- 1         4533 Jan 14 12:08 mfuntort.c
  3451. --rw-r--r-- 1         4187 Jan 13 16:34 norm.c
  3452. --rw-r--r-- 1         3853 Jan 13 16:34 oldnames.h
  3453. --rw-r--r-- 1         4226 Jan 13 16:35 otherio.c
  3454. --rw-r--r-- 1         7497 Mar 24 09:59 pxop.c
  3455. --rw-r--r-- 1        13381 Jan 13 16:35 qrfactor.c
  3456. --rw-r--r-- 1          141 Jan 13 16:49 rk4.dat
  3457. --rw-r--r-- 1        18439 Mar 17 15:38 schur.c
  3458. --rw-r--r-- 1         6553 Jan 13 16:30 solve.c
  3459. --rw-r--r-- 1        23765 Mar 08 15:47 sparse.c
  3460. --rw-r--r-- 1         6483 Jan 13 16:33 sparse.h
  3461. --rw-r--r-- 1         3160 Jan 13 16:33 sparse2.h
  3462. --rw-r--r-- 1         8225 Jan 13 16:34 sparseio.c
  3463. --rw-r--r-- 1        35604 Jan 13 16:44 spbkp.c
  3464. --rw-r--r-- 1        15913 Jan 13 16:31 spchfctr.c
  3465. --rw-r--r-- 1        10808 May 10 09:14 splufctr.c
  3466. --rw-r--r-- 1        17667 Jan 13 16:35 sprow.c
  3467. --rw-r--r-- 1         7408 Jan 13 16:44 spswap.c
  3468. --rw-r--r-- 1        11286 Mar 01 10:22 sptort.c
  3469. --rw-r--r-- 1         4533 Jan 13 16:28 submat.c
  3470. --rw-r--r-- 1         9917 Jan 13 16:44 svd.c
  3471. --rw-r--r-- 1         5967 Feb 16 14:25 symmeig.c
  3472. --rw-r--r-- 1        28139 May 18 11:54 torture.c
  3473. --rw-r--r-- 1         4499 Jan 14 14:43 tutadv.c
  3474. --rw-r--r-- 1         7767 Jan 17 09:53 tutorial.c
  3475. --rw-r--r-- 1         3441 Jan 13 16:26 update.c
  3476. --rw-r--r-- 1        13430 Mar 08 15:50 vecop.c
  3477. --rw-r--r-- 1         2562 Mar 24 10:07 version.c
  3478. --rw-r--r-- 1         5204 Jan 13 15:28 zcopy.c
  3479. --rw-r--r-- 1         4411 Jan 13 15:28 zfunc.c
  3480. --rw-r--r-- 1         4801 Mar 08 14:31 zgivens.c
  3481. --rw-r--r-- 1         3948 Jan 13 15:27 zhessen.c
  3482. --rw-r--r-- 1         5532 Apr 07 11:44 zhsehldr.c
  3483. --rw-r--r-- 1         6892 Jan 13 15:26 zlufctr.c
  3484. --rw-r--r-- 1         4255 Jan 13 15:26 zmachine.c
  3485. --rw-r--r-- 1        10649 Jan 13 15:25 zmatio.c
  3486. --rw-r--r-- 1         5845 Jan 13 15:25 zmatlab.c
  3487. --rw-r--r-- 1        15253 Jan 13 15:24 zmatop.c
  3488. --rw-r--r-- 1         8782 Mar 08 15:50 zmatrix.h
  3489. --rw-r--r-- 1         4151 Jan 13 15:24 zmatrix2.h
  3490. --rw-r--r-- 1        15275 Apr 05 12:13 zmemory.c
  3491. --rw-r--r-- 1         4624 Jan 13 15:21 znorm.c
  3492. --rw-r--r-- 1        13780 Jan 13 15:21 zqrfctr.c
  3493. --rw-r--r-- 1        10977 Jan 13 15:21 zschur.c
  3494. --rw-r--r-- 1         7573 Jan 13 15:20 zsolve.c
  3495. --rw-r--r-- 1        20049 Apr 12 12:29 ztorture.c
  3496. --rw-r--r-- 1        11225 Mar 08 15:51 zvecop.c
  3497. -
  3498. -DOC:
  3499. -total 136
  3500. --rw-r----- 1        17186 Jan 14 12:01 fnindex.txt
  3501. --rw-r----- 1        45980 Jan 14 12:01 tutorial.txt
  3502. -
  3503. -MACHINES:
  3504. -total 32
  3505. -drwxr-s--- 2          512 Jan 14 14:24 GCC
  3506. -drwxr-s--- 2          512 Mar 03 09:52 Linux
  3507. -drwxr-s--- 2          512 Feb 14 12:08 RS6000
  3508. -drwxr-s--- 2          512 Jan 14 14:24 SPARC
  3509. -
  3510. -MACHINES/GCC:
  3511. -total 24
  3512. --rw-r----- 1         3775 Jan 14 14:24 machine.h
  3513. --rw-r----- 1         5183 Jan 14 14:24 makefile
  3514. -
  3515. -MACHINES/Linux:
  3516. -total 24
  3517. --rw-r----- 1         3820 Mar 03 09:52 machine.h
  3518. --rw-r----- 1         5595 Mar 03 09:52 makefile
  3519. -
  3520. -MACHINES/RS6000:
  3521. -total 40
  3522. --rw-r----- 1         6129 Jan 25 09:39 machine.c
  3523. --rw-r----- 1         3502 Jan 14 14:24 machine.h
  3524. --rw-r----- 1         5654 Feb 14 12:07 makefile
  3525. -
  3526. -MACHINES/SPARC:
  3527. -total 24
  3528. --rw-r----- 1         3524 Jan 14 14:24 machine.h
  3529. --rw-r----- 1         5186 Jan 14 14:24 makefile
  3530. //GO.SYSIN DD FILELIST
  3531. echo torture.c 1>&2
  3532. sed >torture.c <<'//GO.SYSIN DD torture.c' 's/^-//'
  3533. -
  3534. -/**************************************************************************
  3535. -**
  3536. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  3537. -**
  3538. -**                 Meschach Library
  3539. -** 
  3540. -** This Meschach Library is provided "as is" without any express 
  3541. -** or implied warranty of any kind with respect to this software. 
  3542. -** In particular the authors shall not be liable for any direct, 
  3543. -** indirect, special, incidental or consequential damages arising 
  3544. -** in any way from use of the software.
  3545. -** 
  3546. -** Everyone is granted permission to copy, modify and redistribute this
  3547. -** Meschach Library, provided:
  3548. -**  1.  All copies contain this copyright notice.
  3549. -**  2.  All modified copies shall carry a notice stating who
  3550. -**      made the last modification and the date of such modification.
  3551. -**  3.  No charge is made for this software or works derived from it.  
  3552. -**      This clause shall not be construed as constraining other software
  3553. -**      distributed on the same medium as this software, nor is a
  3554. -**      distribution fee considered a charge.
  3555. -**
  3556. -***************************************************************************/
  3557. -
  3558. -/*
  3559. -    This file contains a series of tests for the Meschach matrix
  3560. -    library, parts 1 and 2
  3561. -*/
  3562. -
  3563. -static char rcsid[] = "$Id: torture.c,v 1.5 1994/05/18 01:53:58 des Exp $";
  3564. -
  3565. -#include    <stdio.h>
  3566. -#include    <math.h>
  3567. -#include    "matrix2.h"
  3568. -#include        "matlab.h"
  3569. -
  3570. -#define    errmesg(mesg)    printf("Error: %s error: line %d\n",mesg,__LINE__)
  3571. -#define notice(mesg)    printf("# Testing %s...\n",mesg);
  3572. -
  3573. -static char *test_err_list[] = {
  3574. -   "unknown error",            /* 0 */
  3575. -   "testing error messages",        /* 1 */
  3576. -   "unexpected end-of-file"        /* 2 */
  3577. -};
  3578. -
  3579. -
  3580. -#define MAX_TEST_ERR   (sizeof(test_err_list)/sizeof(char *))
  3581. -
  3582. -/* extern    int    malloc_chain_check(); */
  3583. -/* #define MEMCHK() if ( malloc_chain_check(0) ) \
  3584. -{ printf("Error in malloc chain: \"%s\", line %d\n", \
  3585. -     __FILE__, __LINE__); exit(0); } */
  3586. -#define    MEMCHK() 
  3587. -
  3588. -/* cmp_perm -- returns 1 if pi1 == pi2, 0 otherwise */
  3589. -int    cmp_perm(pi1, pi2)
  3590. -PERM    *pi1, *pi2;
  3591. -{
  3592. -    int        i;
  3593. -
  3594. -    if ( ! pi1 || ! pi2 )
  3595. -    error(E_NULL,"cmp_perm");
  3596. -    if ( pi1->size != pi2->size )
  3597. -    return 0;
  3598. -    for ( i = 0; i < pi1->size; i++ )
  3599. -    if ( pi1->pe[i] != pi2->pe[i] )
  3600. -        return 0;
  3601. -    return 1;
  3602. -}
  3603. -
  3604. -/* px_rand -- generates sort-of random permutation */
  3605. -PERM    *px_rand(pi)
  3606. -PERM    *pi;
  3607. -{
  3608. -    int        i, j, k;
  3609. -
  3610. -    if ( ! pi )
  3611. -    error(E_NULL,"px_rand");
  3612. -
  3613. -    for ( i = 0; i < 3*pi->size; i++ )
  3614. -    {
  3615. -    j = (rand() >> 8) % pi->size;
  3616. -    k = (rand() >> 8) % pi->size;
  3617. -    px_transp(pi,j,k);
  3618. -    }
  3619. -
  3620. -    return pi;
  3621. -}
  3622. -
  3623. -#define    SAVE_FILE    "asx5213a.mat"
  3624. -#define    MATLAB_NAME    "alpha"
  3625. -char    name[81] = MATLAB_NAME;
  3626. -
  3627. -int main(argc, argv)
  3628. -int    argc;
  3629. -char    *argv[];
  3630. -{
  3631. -   VEC    *x = VNULL, *y = VNULL, *z = VNULL, *u = VNULL, *v = VNULL, 
  3632. -        *w = VNULL;
  3633. -   VEC    *diag = VNULL, *beta = VNULL;
  3634. -   PERM    *pi1 = PNULL, *pi2 = PNULL, *pi3 = PNULL, *pivot = PNULL, 
  3635. -        *blocks = PNULL;
  3636. -   MAT    *A = MNULL, *Atmp = MNULL, *B = MNULL, *C = MNULL, *D = MNULL,
  3637. -        *Q = MNULL, *Qtmp = MNULL, *U = MNULL;
  3638. -   BAND *bA, *bB, *bC;
  3639. -   Real    cond_est, s1, s2, s3;
  3640. -   int    i, j, seed;
  3641. -   FILE    *fp;
  3642. -   char    *cp;
  3643. -
  3644. -
  3645. -    mem_info_on(TRUE);
  3646. -
  3647. -    setbuf(stdout,(char *)NULL);
  3648. -
  3649. -    seed = 1111;
  3650. -    if ( argc > 2 )
  3651. -    {
  3652. -    printf("usage: %s [seed]\n",argv[0]);
  3653. -    exit(0);
  3654. -    }
  3655. -    else if ( argc == 2 )
  3656. -    sscanf(argv[1], "%d", &seed);
  3657. -
  3658. -    /* set seed for rand() */
  3659. -    smrand(seed);
  3660. -
  3661. -    mem_stat_mark(1);
  3662. -
  3663. -    /* print version information */
  3664. -    m_version();
  3665. -
  3666. -    printf("# grep \"^Error\" the output for a listing of errors\n");
  3667. -    printf("# Don't panic if you see \"Error\" appearing; \n");
  3668. -    printf("# Also check the reported size of error\n");
  3669. -    printf("# This program uses randomly generated problems and therefore\n");
  3670. -    printf("# may occasionally produce ill-conditioned problems\n");
  3671. -    printf("# Therefore check the size of the error compared with MACHEPS\n");
  3672. -    printf("# If the error is within 1000*MACHEPS then don't worry\n");
  3673. -    printf("# If you get an error of size 0.1 or larger there is \n");
  3674. -    printf("# probably a bug in the code or the compilation procedure\n\n");
  3675. -    printf("# seed = %d\n",seed);
  3676. -
  3677. -    printf("# Check: MACHEPS = %g\n",MACHEPS);
  3678. -    /* allocate, initialise, copy and resize operations */
  3679. -    /* VEC */
  3680. -    notice("vector initialise, copy & resize");
  3681. -    x = v_get(12);
  3682. -    y = v_get(15);
  3683. -    z = v_get(12);
  3684. -    v_rand(x);
  3685. -    v_rand(y);
  3686. -    z = v_copy(x,z);
  3687. -    if ( v_norm2(v_sub(x,z,z)) >= MACHEPS )
  3688. -    errmesg("VEC copy");
  3689. -    v_copy(x,y);
  3690. -    x = v_resize(x,10);
  3691. -    y = v_resize(y,10);
  3692. -    if ( v_norm2(v_sub(x,y,z)) >= MACHEPS )
  3693. -    errmesg("VEC copy/resize");
  3694. -    x = v_resize(x,15);
  3695. -    y = v_resize(y,15);
  3696. -    if ( v_norm2(v_sub(x,y,z)) >= MACHEPS )
  3697. -    errmesg("VEC resize");
  3698. -
  3699. -    /* MAT */
  3700. -    notice("matrix initialise, copy & resize");
  3701. -    A = m_get(8,5);
  3702. -    B = m_get(3,9);
  3703. -    C = m_get(8,5);
  3704. -    m_rand(A);
  3705. -    m_rand(B);
  3706. -    C = m_copy(A,C);
  3707. -    if ( m_norm_inf(m_sub(A,C,C)) >= MACHEPS )
  3708. -    errmesg("MAT copy");
  3709. -    m_copy(A,B);
  3710. -    A = m_resize(A,3,5);
  3711. -    B = m_resize(B,3,5);
  3712. -    if ( m_norm_inf(m_sub(A,B,C)) >= MACHEPS )
  3713. -    errmesg("MAT copy/resize");
  3714. -    A = m_resize(A,10,10);
  3715. -    B = m_resize(B,10,10);
  3716. -    if ( m_norm_inf(m_sub(A,B,C)) >= MACHEPS )
  3717. -    errmesg("MAT resize");
  3718. -
  3719. -    MEMCHK();
  3720. -
  3721. -    /* PERM */
  3722. -    notice("permutation initialise, inverting & permuting vectors");
  3723. -    pi1 = px_get(15);
  3724. -    pi2 = px_get(12);
  3725. -    px_rand(pi1);
  3726. -    v_rand(x);
  3727. -    px_vec(pi1,x,z);
  3728. -    y = v_resize(y,x->dim);
  3729. -    pxinv_vec(pi1,z,y);
  3730. -    if ( v_norm2(v_sub(x,y,z)) >= MACHEPS )
  3731. -    errmesg("PERMute vector");
  3732. -    pi2 = px_inv(pi1,pi2);
  3733. -    pi3 = px_mlt(pi1,pi2,PNULL);
  3734. -    for ( i = 0; i < pi3->size; i++ )
  3735. -    if ( pi3->pe[i] != i )
  3736. -        errmesg("PERM inverse/multiply");
  3737. -
  3738. -    /* testing catch() etc */
  3739. -    notice("error handling routines");
  3740. -    catch(E_NULL,
  3741. -      catchall(v_add(VNULL,VNULL,VNULL);
  3742. -             errmesg("tracecatch() failure"),
  3743. -             printf("# tracecatch() caught error\n");
  3744. -             error(E_NULL,"main"));
  3745. -                 errmesg("catch() failure"),
  3746. -      printf("# catch() caught E_NULL error\n"));
  3747. -
  3748. -    /* testing attaching a new error list (error list 2) */
  3749. -
  3750. -    notice("attaching error lists");
  3751. -    printf("# IT IS NOT A REAL WARNING ... \n");
  3752. -    err_list_attach(2,MAX_TEST_ERR,test_err_list,TRUE);
  3753. -    if (!err_is_list_attached(2)) 
  3754. -       errmesg("attaching the error list 2");
  3755. -    ev_err(__FILE__,1,__LINE__,"main",2);
  3756. -    err_list_free(2);
  3757. -    if (err_is_list_attached(2)) 
  3758. -       errmesg("detaching the error list 2");
  3759. -
  3760. -    /* testing inner products and v_mltadd() etc */
  3761. -    notice("inner products and linear combinations");
  3762. -    u = v_get(x->dim);
  3763. -    v_rand(u);
  3764. -    v_rand(x);
  3765. -    v_resize(y,x->dim);
  3766. -    v_rand(y);
  3767. -    v_mltadd(y,x,-in_prod(x,y)/in_prod(x,x),z);
  3768. -    if ( fabs(in_prod(x,z)) >= MACHEPS*x->dim )
  3769. -    errmesg("v_mltadd()/in_prod()");
  3770. -    s1 = -in_prod(x,y)/(v_norm2(x)*v_norm2(x));
  3771. -    sv_mlt(s1,x,u);
  3772. -    v_add(y,u,u);
  3773. -    if ( v_norm2(v_sub(u,z,u)) >= MACHEPS*x->dim )
  3774. -    errmesg("sv_mlt()/v_norm2()");
  3775. -
  3776. -#ifdef ANSI_C 
  3777. -    v_linlist(u,x,s1,y,1.0,VNULL);
  3778. -    if ( v_norm2(v_sub(u,z,u)) >= MACHEPS*x->dim )
  3779. -    errmesg("v_linlist()");
  3780. -#endif
  3781. -#ifdef VARARGS
  3782. -    v_linlist(u,x,s1,y,1.0,VNULL);
  3783. -    if ( v_norm2(v_sub(u,z,u)) >= MACHEPS*x->dim )
  3784. -    errmesg("v_linlist()");
  3785. -#endif
  3786. -
  3787. -
  3788. -    MEMCHK();
  3789. -
  3790. -    /* vector norms */
  3791. -    notice("vector norms");
  3792. -    x = v_resize(x,12);
  3793. -    v_rand(x);
  3794. -    for ( i = 0; i < x->dim; i++ )
  3795. -    if ( v_entry(x,i) >= 0.5 )
  3796. -        v_set_val(x,i,1.0);
  3797. -        else
  3798. -        v_set_val(x,i,-1.0);
  3799. -    s1 = v_norm1(x);
  3800. -    s2 = v_norm2(x);    
  3801. -    s3 = v_norm_inf(x);
  3802. -    if ( fabs(s1 - x->dim) >= MACHEPS*x->dim ||
  3803. -     fabs(s2 - sqrt((Real)(x->dim))) >= MACHEPS*x->dim ||
  3804. -     fabs(s3 - 1.0) >= MACHEPS )
  3805. -    errmesg("v_norm1/2/_inf()");
  3806. -
  3807. -    /* test matrix multiply etc */
  3808. -    notice("matrix multiply and invert");
  3809. -    A = m_resize(A,10,10);
  3810. -    B = m_resize(B,10,10);
  3811. -    m_rand(A);
  3812. -    m_inverse(A,B);
  3813. -    m_mlt(A,B,C);
  3814. -    for ( i = 0; i < C->m; i++ )
  3815. -    m_set_val(C,i,i,m_entry(C,i,i)-1.0);
  3816. -    if ( m_norm_inf(C) >= MACHEPS*m_norm_inf(A)*m_norm_inf(B)*5 )
  3817. -    errmesg("m_inverse()/m_mlt()");
  3818. -
  3819. -    MEMCHK();
  3820. -
  3821. -    /* ... and transposes */
  3822. -    notice("transposes and transpose-multiplies");
  3823. -    m_transp(A,A);    /* can do square matrices in situ */
  3824. -    mtrm_mlt(A,B,C);
  3825. -    for ( i = 0; i < C->m; i++ )
  3826. -    m_set_val(C,i,i,m_entry(C,i,i)-1.0);
  3827. -    if ( m_norm_inf(C) >= MACHEPS*m_norm_inf(A)*m_norm_inf(B)*5 )
  3828. -    errmesg("m_transp()/mtrm_mlt()");
  3829. -    m_transp(A,A);
  3830. -    m_transp(B,B);
  3831. -    mmtr_mlt(A,B,C);
  3832. -    for ( i = 0; i < C->m; i++ )
  3833. -    m_set_val(C,i,i,m_entry(C,i,i)-1.0);
  3834. -    if ( m_norm_inf(C) >= MACHEPS*m_norm_inf(A)*m_norm_inf(B)*5 )
  3835. -    errmesg("m_transp()/mmtr_mlt()");
  3836. -    sm_mlt(3.71,B,B);
  3837. -    mmtr_mlt(A,B,C);
  3838. -    for ( i = 0; i < C->m; i++ )
  3839. -    m_set_val(C,i,i,m_entry(C,i,i)-3.71);
  3840. -    if ( m_norm_inf(C) >= MACHEPS*m_norm_inf(A)*m_norm_inf(B)*5 )
  3841. -    errmesg("sm_mlt()/mmtr_mlt()");
  3842. -    m_transp(B,B);
  3843. -    sm_mlt(1.0/3.71,B,B);
  3844. -
  3845. -    MEMCHK();
  3846. -
  3847. -    /* ... and matrix-vector multiplies */
  3848. -    notice("matrix-vector multiplies");
  3849. -    x = v_resize(x,A->n);
  3850. -    y = v_resize(y,A->m);
  3851. -    z = v_resize(z,A->m);
  3852. -    u = v_resize(u,A->n);
  3853. -    v_rand(x);
  3854. -    v_rand(y);
  3855. -    mv_mlt(A,x,z);
  3856. -    s1 = in_prod(y,z);
  3857. -    vm_mlt(A,y,u);
  3858. -    s2 = in_prod(u,x);
  3859. -    if ( fabs(s1 - s2) >= (MACHEPS*x->dim)*x->dim )
  3860. -    errmesg("mv_mlt()/vm_mlt()");
  3861. -    mv_mlt(B,z,u);
  3862. -    if ( v_norm2(v_sub(u,x,u)) >= MACHEPS*m_norm_inf(A)*m_norm_inf(B)*5 )
  3863. -    errmesg("mv_mlt()/m_inverse()");
  3864. -
  3865. -    MEMCHK();
  3866. -
  3867. -    /* get/set row/col */
  3868. -    notice("getting and setting rows and cols");
  3869. -    x = v_resize(x,A->n);
  3870. -    y = v_resize(y,B->m);
  3871. -    x = get_row(A,3,x);
  3872. -    y = get_col(B,3,y);
  3873. -    if ( fabs(in_prod(x,y) - 1.0) >= MACHEPS*m_norm_inf(A)*m_norm_inf(B)*5 )
  3874. -    errmesg("get_row()/get_col()");
  3875. -    sv_mlt(-1.0,x,x);
  3876. -    sv_mlt(-1.0,y,y);
  3877. -    set_row(A,3,x);
  3878. -    set_col(B,3,y);
  3879. -    m_mlt(A,B,C);
  3880. -    for ( i = 0; i < C->m; i++ )
  3881. -    m_set_val(C,i,i,m_entry(C,i,i)-1.0);
  3882. -    if ( m_norm_inf(C) >= MACHEPS*m_norm_inf(A)*m_norm_inf(B)*5 )
  3883. -    errmesg("set_row()/set_col()");
  3884. -
  3885. -    MEMCHK();
  3886. -
  3887. -    /* matrix norms */
  3888. -    notice("matrix norms");
  3889. -    A = m_resize(A,11,15);
  3890. -    m_rand(A);
  3891. -    s1 = m_norm_inf(A);
  3892. -    B = m_transp(A,B);
  3893. -    s2 = m_norm1(B);
  3894. -    if ( fabs(s1 - s2) >= MACHEPS*A->m )
  3895. -    errmesg("m_norm1()/m_norm_inf()");
  3896. -    C = mtrm_mlt(A,A,C);
  3897. -    s1 = 0.0;
  3898. -    for ( i = 0; i < C->m && i < C->n; i++ )
  3899. -    s1 += m_entry(C,i,i);
  3900. -    if ( fabs(sqrt(s1) - m_norm_frob(A)) >= MACHEPS*A->m*A->n )
  3901. -    errmesg("m_norm_frob");
  3902. -
  3903. -    MEMCHK();
  3904. -    
  3905. -    /* permuting rows and columns */
  3906. -    notice("permuting rows & cols");
  3907. -    A = m_resize(A,11,15);
  3908. -    B = m_resize(B,11,15);
  3909. -    pi1 = px_resize(pi1,A->m);
  3910. -    px_rand(pi1);
  3911. -    x = v_resize(x,A->n);
  3912. -    y = mv_mlt(A,x,y);
  3913. -    px_rows(pi1,A,B);
  3914. -    px_vec(pi1,y,z);
  3915. -    mv_mlt(B,x,u);
  3916. -    if ( v_norm2(v_sub(z,u,u)) >= MACHEPS*A->m )
  3917. -    errmesg("px_rows()");
  3918. -    pi1 = px_resize(pi1,A->n);
  3919. -    px_rand(pi1);
  3920. -    px_cols(pi1,A,B);
  3921. -    pxinv_vec(pi1,x,z);
  3922. -    mv_mlt(B,z,u);
  3923. -    if ( v_norm2(v_sub(y,u,u)) >= MACHEPS*A->n )
  3924. -    errmesg("px_cols()");
  3925. -
  3926. -    MEMCHK();
  3927. -
  3928. -    /* MATLAB save/load */
  3929. -    notice("MATLAB save/load");
  3930. -    A = m_resize(A,12,11);
  3931. -    if ( (fp=fopen(SAVE_FILE,"w")) == (FILE *)NULL )
  3932. -    printf("Cannot perform MATLAB save/load test\n");
  3933. -    else
  3934. -    {
  3935. -    m_rand(A);
  3936. -    m_save(fp, A, name);
  3937. -    fclose(fp);
  3938. -    if ( (fp=fopen(SAVE_FILE,"r")) == (FILE *)NULL )
  3939. -        printf("Cannot open save file \"%s\"\n",SAVE_FILE);
  3940. -    else
  3941. -    {
  3942. -        M_FREE(B);
  3943. -        B = m_load(fp,&cp);
  3944. -        if ( strcmp(name,cp) || m_norm1(m_sub(A,B,B)) >= MACHEPS*A->m )
  3945. -        errmesg("mload()/m_save()");
  3946. -    }
  3947. -    }
  3948. -
  3949. -    MEMCHK();
  3950. -
  3951. -    /* Now, onto matrix factorisations */
  3952. -    A = m_resize(A,10,10);
  3953. -    B = m_resize(B,A->m,A->n);
  3954. -    m_copy(A,B);
  3955. -    x = v_resize(x,A->n);
  3956. -    y = v_resize(y,A->m);
  3957. -    z = v_resize(z,A->n);
  3958. -    u = v_resize(u,A->m);
  3959. -    v_rand(x);
  3960. -    mv_mlt(B,x,y);
  3961. -    z = v_copy(x,z);
  3962. -
  3963. -    notice("LU factor/solve");
  3964. -    pivot = px_get(A->m);
  3965. -    LUfactor(A,pivot);
  3966. -    tracecatch(LUsolve(A,pivot,y,x),"main");
  3967. -    tracecatch(cond_est = LUcondest(A,pivot),"main");
  3968. -    printf("# cond(A) approx= %g\n", cond_est);
  3969. -    if ( v_norm2(v_sub(x,z,u)) >= MACHEPS*v_norm2(x)*cond_est)
  3970. -    {
  3971. -    errmesg("LUfactor()/LUsolve()");
  3972. -    printf("# LU solution error = %g [cf MACHEPS = %g]\n",
  3973. -           v_norm2(v_sub(x,z,u)), MACHEPS);
  3974. -    }
  3975. -
  3976. -    v_copy(y,x);
  3977. -    tracecatch(LUsolve(A,pivot,x,x),"main");
  3978. -    tracecatch(cond_est = LUcondest(A,pivot),"main");
  3979. -    if ( v_norm2(v_sub(x,z,u)) >= MACHEPS*v_norm2(x)*cond_est)
  3980. -    {
  3981. -    errmesg("LUfactor()/LUsolve()");
  3982. -    printf("# LU solution error = %g [cf MACHEPS = %g]\n",
  3983. -           v_norm2(v_sub(x,z,u)), MACHEPS);
  3984. -    }
  3985. -
  3986. -    vm_mlt(B,z,y);
  3987. -    v_copy(y,x);
  3988. -    tracecatch(LUTsolve(A,pivot,x,x),"main");
  3989. -    if ( v_norm2(v_sub(x,z,u)) >= MACHEPS*v_norm2(x)*cond_est)
  3990. -    {
  3991. -    errmesg("LUfactor()/LUTsolve()");
  3992. -    printf("# LU solution error = %g [cf MACHEPS = %g]\n",
  3993. -           v_norm2(v_sub(x,z,u)), MACHEPS);
  3994. -    }
  3995. -    MEMCHK();
  3996. -
  3997. -    /* QR factorisation */
  3998. -    m_copy(B,A);
  3999. -    mv_mlt(B,z,y);
  4000. -    notice("QR factor/solve:");
  4001. -    diag = v_get(A->m);
  4002. -    beta = v_get(A->m);
  4003. -    QRfactor(A,diag);
  4004. -    QRsolve(A,diag,y,x);
  4005. -    if ( v_norm2(v_sub(x,z,u)) >= MACHEPS*v_norm2(x)*cond_est )
  4006. -    {
  4007. -    errmesg("QRfactor()/QRsolve()");
  4008. -    printf("# QR solution error = %g [cf MACHEPS = %g]\n",
  4009. -           v_norm2(v_sub(x,z,u)), MACHEPS);
  4010. -    }
  4011. -    Q = m_get(A->m,A->m);
  4012. -    makeQ(A,diag,Q);
  4013. -    makeR(A,A);
  4014. -    m_mlt(Q,A,C);
  4015. -    m_sub(B,C,C);
  4016. -    if ( m_norm1(C) >= MACHEPS*m_norm1(Q)*m_norm1(B) )
  4017. -    {
  4018. -    errmesg("QRfactor()/makeQ()/makeR()");
  4019. -    printf("# QR reconstruction error = %g [cf MACHEPS = %g]\n",
  4020. -           m_norm1(C), MACHEPS);
  4021. -    }
  4022. -
  4023. -    MEMCHK();
  4024. -
  4025. -    /* now try with a non-square matrix */
  4026. -    A = m_resize(A,15,7);
  4027. -    m_rand(A);
  4028. -    B = m_copy(A,B);
  4029. -    diag = v_resize(diag,A->n);
  4030. -    beta = v_resize(beta,A->n);
  4031. -    x = v_resize(x,A->n);
  4032. -    y = v_resize(y,A->m);
  4033. -    v_rand(y);
  4034. -    QRfactor(A,diag);
  4035. -    x = QRsolve(A,diag,y,x);
  4036. -    /* z is the residual vector */
  4037. -    mv_mlt(B,x,z);    v_sub(z,y,z);
  4038. -    /* check B^T.z = 0 */
  4039. -    vm_mlt(B,z,u);
  4040. -    if ( v_norm2(u) >= MACHEPS*m_norm1(B)*v_norm2(y) )
  4041. -    {
  4042. -    errmesg("QRfactor()/QRsolve()");
  4043. -    printf("# QR solution error = %g [cf MACHEPS = %g]\n",
  4044. -           v_norm2(u), MACHEPS);
  4045. -    }
  4046. -    Q = m_resize(Q,A->m,A->m);
  4047. -    makeQ(A,diag,Q);
  4048. -    makeR(A,A);
  4049. -    m_mlt(Q,A,C);
  4050. -    m_sub(B,C,C);
  4051. -    if ( m_norm1(C) >= MACHEPS*m_norm1(Q)*m_norm1(B) )
  4052. -    {
  4053. -    errmesg("QRfactor()/makeQ()/makeR()");
  4054. -    printf("# QR reconstruction error = %g [cf MACHEPS = %g]\n",
  4055. -           m_norm1(C), MACHEPS);
  4056. -    }
  4057. -    D = m_get(A->m,Q->m);
  4058. -    mtrm_mlt(Q,Q,D);
  4059. -    for ( i = 0; i < D->m; i++ )
  4060. -    m_set_val(D,i,i,m_entry(D,i,i)-1.0);
  4061. -    if ( m_norm1(D) >= MACHEPS*m_norm1(Q)*m_norm_inf(Q) )
  4062. -    {
  4063. -    errmesg("QRfactor()/makeQ()/makeR()");
  4064. -    printf("# QR orthogonality error = %g [cf MACHEPS = %g]\n",
  4065. -           m_norm1(D), MACHEPS);
  4066. -    }
  4067. -
  4068. -    MEMCHK();
  4069. -
  4070. -    /* QRCP factorisation */
  4071. -    m_copy(B,A);
  4072. -    notice("QR factor/solve with column pivoting");
  4073. -    pivot = px_resize(pivot,A->n);
  4074. -    QRCPfactor(A,diag,pivot);
  4075. -    z = v_resize(z,A->n);
  4076. -    QRCPsolve(A,diag,pivot,y,z);
  4077. -    /* pxinv_vec(pivot,z,x); */
  4078. -    /* now compute residual (z) vector */
  4079. -    mv_mlt(B,x,z);    v_sub(z,y,z);
  4080. -    /* check B^T.z = 0 */
  4081. -    vm_mlt(B,z,u);
  4082. -    if ( v_norm2(u) >= MACHEPS*m_norm1(B)*v_norm2(y) )
  4083. -    {
  4084. -    errmesg("QRCPfactor()/QRsolve()");
  4085. -    printf("# QR solution error = %g [cf MACHEPS = %g]\n",
  4086. -           v_norm2(u), MACHEPS);
  4087. -    }
  4088. -
  4089. -    Q = m_resize(Q,A->m,A->m);
  4090. -    makeQ(A,diag,Q);
  4091. -    makeR(A,A);
  4092. -    m_mlt(Q,A,C);
  4093. -    M_FREE(D);
  4094. -    D = m_get(B->m,B->n);
  4095. -    px_cols(pivot,C,D);
  4096. -    m_sub(B,D,D);
  4097. -    if ( m_norm1(D) >= MACHEPS*m_norm1(Q)*m_norm1(B) )
  4098. -    {
  4099. -    errmesg("QRCPfactor()/makeQ()/makeR()");
  4100. -    printf("# QR reconstruction error = %g [cf MACHEPS = %g]\n",
  4101. -           m_norm1(D), MACHEPS);
  4102. -    }
  4103. -
  4104. -    MEMCHK();
  4105. -
  4106. -    /* Cholesky and LDL^T factorisation */
  4107. -    /* Use these for normal equations approach */
  4108. -    notice("Cholesky factor/solve");
  4109. -    mtrm_mlt(B,B,A);
  4110. -    CHfactor(A);
  4111. -    u = v_resize(u,B->n);
  4112. -    vm_mlt(B,y,u);
  4113. -    z = v_resize(z,B->n);
  4114. -    CHsolve(A,u,z);
  4115. -    v_sub(x,z,z);
  4116. -    if ( v_norm2(z) >= MACHEPS*v_norm2(x)*100 )
  4117. -    {
  4118. -    errmesg("CHfactor()/CHsolve()");
  4119. -    printf("# Cholesky solution error = %g [cf MACHEPS = %g]\n",
  4120. -           v_norm2(z), MACHEPS);
  4121. -    }
  4122. -    /* modified Cholesky factorisation should be identical with Cholesky
  4123. -       factorisation provided the matrix is "sufficiently positive definite */
  4124. -    mtrm_mlt(B,B,C);
  4125. -    MCHfactor(C,MACHEPS);
  4126. -    m_sub(A,C,C);
  4127. -    if ( m_norm1(C) >= MACHEPS*m_norm1(A) )
  4128. -    {
  4129. -    errmesg("MCHfactor()");
  4130. -    printf("# Modified Cholesky error = %g [cf MACHEPS = %g]\n",
  4131. -           m_norm1(C), MACHEPS);
  4132. -    }
  4133. -    /* now test the LDL^T factorisation -- using a negative def. matrix */
  4134. -    mtrm_mlt(B,B,A);
  4135. -    sm_mlt(-1.0,A,A);
  4136. -    m_copy(A,C);
  4137. -    LDLfactor(A);
  4138. -    LDLsolve(A,u,z);
  4139. -    w = v_get(A->m);
  4140. -    mv_mlt(C,z,w);
  4141. -    v_sub(w,u,w);
  4142. -    if ( v_norm2(w) >= MACHEPS*v_norm2(u)*m_norm1(C) )
  4143. -    {
  4144. -    errmesg("LDLfactor()/LDLsolve()");
  4145. -    printf("# LDL^T residual = %g [cf MACHEPS = %g]\n",
  4146. -           v_norm2(w), MACHEPS);
  4147. -    }
  4148. -    v_add(x,z,z);
  4149. -    if ( v_norm2(z) >= MACHEPS*v_norm2(x)*100 )
  4150. -    {
  4151. -    errmesg("LDLfactor()/LDLsolve()");
  4152. -    printf("# LDL^T solution error = %g [cf MACHEPS = %g]\n",
  4153. -           v_norm2(z), MACHEPS);
  4154. -    }
  4155. -
  4156. -    MEMCHK();
  4157. -
  4158. -    /* and now the Bunch-Kaufman-Parlett method */
  4159. -    /* set up D to be an indefinite diagonal matrix */
  4160. -    notice("Bunch-Kaufman-Parlett factor/solve");
  4161. -
  4162. -    D = m_resize(D,B->m,B->m);
  4163. -    m_zero(D);
  4164. -    w = v_resize(w,B->m);
  4165. -    v_rand(w);
  4166. -    for ( i = 0; i < w->dim; i++ )
  4167. -    if ( v_entry(w,i) >= 0.5 )
  4168. -        m_set_val(D,i,i,1.0);
  4169. -    else
  4170. -        m_set_val(D,i,i,-1.0);
  4171. -    /* set A <- B^T.D.B */
  4172. -    C = m_resize(C,B->n,B->n);
  4173. -    C = mtrm_mlt(B,D,C);
  4174. -    A = m_mlt(C,B,A);
  4175. -    C = m_resize(C,B->n,B->n);
  4176. -    C = m_copy(A,C);
  4177. -    /* ... and use BKPfactor() */
  4178. -    blocks = px_get(A->m);
  4179. -    pivot = px_resize(pivot,A->m);
  4180. -    x = v_resize(x,A->m);
  4181. -    y = v_resize(y,A->m);
  4182. -    z = v_resize(z,A->m);
  4183. -    v_rand(x);
  4184. -    mv_mlt(A,x,y);
  4185. -    BKPfactor(A,pivot,blocks);
  4186. -    printf("# BKP pivot =\n");    px_output(pivot);
  4187. -    printf("# BKP blocks =\n");    px_output(blocks);
  4188. -    BKPsolve(A,pivot,blocks,y,z);
  4189. -    /* compute & check residual */
  4190. -    mv_mlt(C,z,w);
  4191. -    v_sub(w,y,w);
  4192. -    if ( v_norm2(w) >= MACHEPS*m_norm1(C)*v_norm2(z) )
  4193. -    {
  4194. -    errmesg("BKPfactor()/BKPsolve()");
  4195. -    printf("# BKP residual size = %g [cf MACHEPS = %g]\n",
  4196. -           v_norm2(w), MACHEPS);
  4197. -    }
  4198. -
  4199. -    /* check update routines */
  4200. -    /* check LDLupdate() first */
  4201. -    notice("update L.D.L^T routine");
  4202. -    A = mtrm_mlt(B,B,A);
  4203. -    m_resize(C,A->m,A->n);
  4204. -    C = m_copy(A,C);
  4205. -    LDLfactor(A);
  4206. -    s1 = 3.7;
  4207. -    w = v_resize(w,A->m);
  4208. -    v_rand(w);
  4209. -    for ( i = 0; i < C->m; i++ )
  4210. -    for ( j = 0; j < C->n; j++ )
  4211. -        m_set_val(C,i,j,m_entry(C,i,j)+s1*v_entry(w,i)*v_entry(w,j));
  4212. -    LDLfactor(C);
  4213. -    LDLupdate(A,w,s1);
  4214. -    /* zero out strictly upper triangular parts of A and C */
  4215. -    for ( i = 0; i < A->m; i++ )
  4216. -    for ( j = i+1; j < A->n; j++ )
  4217. -    {
  4218. -        m_set_val(A,i,j,0.0);
  4219. -        m_set_val(C,i,j,0.0);
  4220. -    }
  4221. -    if ( m_norm1(m_sub(A,C,C)) >= sqrt(MACHEPS)*m_norm1(A) )
  4222. -    {
  4223. -    errmesg("LDLupdate()");
  4224. -    printf("# LDL update matrix error = %g [cf MACHEPS = %g]\n",
  4225. -           m_norm1(C), MACHEPS);
  4226. -    }
  4227. -
  4228. -
  4229. -    /* BAND MATRICES */
  4230. -
  4231. -#define COL 40
  4232. -#define UDIAG  5
  4233. -#define LDIAG  2
  4234. -
  4235. -   smrand(101);
  4236. -   bA = bd_get(LDIAG,UDIAG,COL);
  4237. -   bB = bd_get(LDIAG,UDIAG,COL);
  4238. -   bC = bd_get(LDIAG,UDIAG,COL);
  4239. -   A = m_resize(A,COL,COL);
  4240. -   B = m_resize(B,COL,COL);
  4241. -   pivot = px_resize(pivot,COL);
  4242. -   x = v_resize(x,COL);
  4243. -   w = v_resize(w,COL);
  4244. -   z = v_resize(z,COL);
  4245. -
  4246. -   m_rand(A); 
  4247. -   /* generate band matrix */
  4248. -   mat2band(A,LDIAG,UDIAG,bA);
  4249. -   band2mat(bA,A);    /* now A is banded */
  4250. -   bB = bd_copy(bA,bB); 
  4251. -
  4252. -   v_rand(x);  
  4253. -   mv_mlt(A,x,w);
  4254. -   z = v_copy(w,z);
  4255. -
  4256. -   notice("band LU factorization");
  4257. -   bdLUfactor(bA,pivot);
  4258. -
  4259. -   /* pivot will be changed */
  4260. -   bdLUsolve(bA,pivot,z,z);
  4261. -   v_sub(x,z,z);
  4262. -   if (v_norm2(z) > v_norm2(x)*sqrt(MACHEPS)) {
  4263. -      errmesg("incorrect solution (band LU factorization)");
  4264. -      printf(" ||exact sol. - computed sol.|| = %g [MACHEPS = %g]\n",
  4265. -         v_norm2(z),MACHEPS);
  4266. -   }
  4267. -
  4268. -   /* solve transpose system */
  4269. -
  4270. -   notice("band LU factorization for transpose system");
  4271. -   m_transp(A,B);
  4272. -   mv_mlt(B,x,w);
  4273. -
  4274. -   bd_copy(bB,bA);
  4275. -   bd_transp(bA,bA);  
  4276. -   /* transposition in situ */
  4277. -   bd_transp(bA,bA);
  4278. -   bd_transp(bA,bB);
  4279. -
  4280. -   bdLUfactor(bB,pivot);
  4281. -
  4282. -   bdLUsolve(bB,pivot,w,z);
  4283. -   v_sub(x,z,z);
  4284. -   if (v_norm2(z) > v_norm2(x)*sqrt(MACHEPS)) {
  4285. -      errmesg("incorrect solution (band transposed LU factorization)");
  4286. -      printf(" ||exact sol. - computed sol.|| = %g [MACHEPS = %g]\n",
  4287. -         v_norm2(z),MACHEPS);
  4288. -   }
  4289. -
  4290. -
  4291. -   /* Cholesky factorization */
  4292. -
  4293. -   notice("band Choleski LDL' factorization");
  4294. -   m_add(A,B,A);  /* symmetric matrix */
  4295. -   for (i=0; i < COL; i++)     /* positive definite */
  4296. -     A->me[i][i] += 2*LDIAG;   
  4297. -
  4298. -   mat2band(A,LDIAG,LDIAG,bA);
  4299. -   band2mat(bA,A);              /* corresponding matrix A */
  4300. -
  4301. -   v_rand(x);
  4302. -   mv_mlt(A,x,w);
  4303. -   z = v_copy(w,z);
  4304. -   
  4305. -   bdLDLfactor(bA);
  4306. -
  4307. -   z = bdLDLsolve(bA,z,z);
  4308. -   v_sub(x,z,z);
  4309. -   if (v_norm2(z) > v_norm2(x)*sqrt(MACHEPS)) {
  4310. -      errmesg("incorrect solution (band LDL' factorization)");
  4311. -      printf(" ||exact sol. - computed sol.|| = %g [MACHEPS = %g]\n",
  4312. -         v_norm2(z),MACHEPS);
  4313. -   }
  4314. -
  4315. -   /* new bandwidths */
  4316. -   m_rand(A);
  4317. -   bA = bd_resize(bA,UDIAG,LDIAG,COL);
  4318. -   bB = bd_resize(bB,UDIAG,LDIAG,COL);
  4319. -   mat2band(A,UDIAG,LDIAG,bA);
  4320. -   band2mat(bA,A);
  4321. -   bd_copy(bA,bB);
  4322. -
  4323. -   mv_mlt(A,x,w);
  4324. -
  4325. -   notice("band LU factorization (resized)");
  4326. -   bdLUfactor(bA,pivot);
  4327. -
  4328. -   /* pivot will be changed */
  4329. -   bdLUsolve(bA,pivot,w,z);
  4330. -   v_sub(x,z,z);
  4331. -   if (v_norm2(z) > v_norm2(x)*sqrt(MACHEPS)) {
  4332. -      errmesg("incorrect solution (band LU factorization)");
  4333. -      printf(" ||exact sol. - computed sol.|| = %g [MACHEPS = %g]\n",
  4334. -         v_norm2(z),MACHEPS);
  4335. -   }
  4336. -
  4337. -   /* testing transposition */
  4338. -
  4339. -   notice("band matrix transposition");
  4340. -   m_zero(bA->mat);
  4341. -   bd_copy(bB,bA);
  4342. -   m_zero(bB->mat);
  4343. -   bd_copy(bA,bB);
  4344. -
  4345. -   bd_transp(bB,bB);
  4346. -   bd_transp(bB,bB);
  4347. -
  4348. -   m_zero(bC->mat);
  4349. -   bd_copy(bB,bC);
  4350. -
  4351. -   m_sub(bA->mat,bC->mat,bC->mat);
  4352. -   if (m_norm_inf(bC->mat) > MACHEPS*bC->mat->n) {
  4353. -      errmesg("band transposition");
  4354. -      printf(" difference ||A - (A')'|| = %g\n",m_norm_inf(bC->mat));
  4355. -   }
  4356. -   bd_free(bA);
  4357. -   bd_free(bB);
  4358. -   bd_free(bC);
  4359. -
  4360. -
  4361. -    MEMCHK();
  4362. -
  4363. -    /* now check QRupdate() routine */
  4364. -    notice("update QR routine");
  4365. -
  4366. -    B = m_resize(B,15,7);
  4367. -    A = m_resize(A,B->m,B->n);
  4368. -    m_copy(B,A);
  4369. -    diag = v_resize(diag,A->n);
  4370. -    beta = v_resize(beta,A->n);
  4371. -    QRfactor(A,diag);
  4372. -    Q = m_resize(Q,A->m,A->m);
  4373. -    makeQ(A,diag,Q);
  4374. -    makeR(A,A);
  4375. -    m_resize(C,A->m,A->n);
  4376. -    w = v_resize(w,A->m);
  4377. -    v = v_resize(v,A->n);
  4378. -    u = v_resize(u,A->m);
  4379. -    v_rand(w);
  4380. -    v_rand(v);
  4381. -    vm_mlt(Q,w,u);
  4382. -    QRupdate(Q,A,u,v);
  4383. -    m_mlt(Q,A,C);
  4384. -    for ( i = 0; i < B->m; i++ )
  4385. -    for ( j = 0; j < B->n; j++ )
  4386. -        m_set_val(B,i,j,m_entry(B,i,j)+v_entry(w,i)*v_entry(v,j));
  4387. -    m_sub(B,C,C);
  4388. -    if ( m_norm1(C) >= MACHEPS*m_norm1(A)*m_norm1(Q)*2 )
  4389. -    {
  4390. -    errmesg("QRupdate()");
  4391. -    printf("# Reconstruction error in QR update = %g [cf MACHEPS = %g]\n",
  4392. -           m_norm1(C), MACHEPS);
  4393. -    }
  4394. -    m_resize(D,Q->m,Q->n);
  4395. -    mtrm_mlt(Q,Q,D);
  4396. -    for ( i = 0; i < D->m; i++ )
  4397. -    m_set_val(D,i,i,m_entry(D,i,i)-1.0);
  4398. -    if ( m_norm1(D) >= 10*MACHEPS*m_norm1(Q)*m_norm_inf(Q) )
  4399. -    {
  4400. -    errmesg("QRupdate()");
  4401. -    printf("# QR update orthogonality error = %g [cf MACHEPS = %g]\n",
  4402. -           m_norm1(D), MACHEPS);
  4403. -    }
  4404. -
  4405. -    /* Now check eigenvalue/SVD routines */
  4406. -    notice("eigenvalue and SVD routines");
  4407. -    A = m_resize(A,11,11);
  4408. -    B = m_resize(B,A->m,A->n);
  4409. -    C = m_resize(C,A->m,A->n);
  4410. -    D = m_resize(D,A->m,A->n);
  4411. -    Q = m_resize(Q,A->m,A->n);
  4412. -
  4413. -    m_rand(A);
  4414. -    /* A <- A + A^T  for symmetric case */
  4415. -    m_add(A,m_transp(A,C),A);
  4416. -    u = v_resize(u,A->m);
  4417. -    u = symmeig(A,Q,u);
  4418. -    m_zero(B);
  4419. -    for ( i = 0; i < B->m; i++ )
  4420. -    m_set_val(B,i,i,v_entry(u,i));
  4421. -    m_mlt(Q,B,C);
  4422. -    mmtr_mlt(C,Q,D);
  4423. -    m_sub(A,D,D);
  4424. -    if ( m_norm1(D) >= MACHEPS*m_norm1(Q)*m_norm_inf(Q)*v_norm_inf(u)*3 )
  4425. -    {
  4426. -    errmesg("symmeig()");
  4427. -    printf("# Reconstruction error = %g [cf MACHEPS = %g]\n",
  4428. -           m_norm1(D), MACHEPS);
  4429. -    }
  4430. -    mtrm_mlt(Q,Q,D);
  4431. -    for ( i = 0; i < D->m; i++ )
  4432. -    m_set_val(D,i,i,m_entry(D,i,i)-1.0);
  4433. -    if ( m_norm1(D) >= MACHEPS*m_norm1(Q)*m_norm_inf(Q)*3 )
  4434. -    {
  4435. -    errmesg("symmeig()");
  4436. -    printf("# symmeig() orthogonality error = %g [cf MACHEPS = %g]\n",
  4437. -           m_norm1(D), MACHEPS);
  4438. -    }
  4439. -
  4440. -    MEMCHK();
  4441. -
  4442. -    /* now test (real) Schur decomposition */
  4443. -    /* m_copy(A,B); */
  4444. -    M_FREE(A);
  4445. -    A = m_get(11,11);
  4446. -    m_rand(A);
  4447. -    B = m_copy(A,B);
  4448. -    MEMCHK();
  4449. -
  4450. -    B = schur(B,Q);
  4451. -    MEMCHK();
  4452. -
  4453. -    m_mlt(Q,B,C);
  4454. -    mmtr_mlt(C,Q,D);
  4455. -    MEMCHK();
  4456. -    m_sub(A,D,D);
  4457. -    if ( m_norm1(D) >= MACHEPS*m_norm1(Q)*m_norm_inf(Q)*m_norm1(B)*5 )
  4458. -    {
  4459. -    errmesg("schur()");
  4460. -    printf("# Schur reconstruction error = %g [cf MACHEPS = %g]\n",
  4461. -           m_norm1(D), MACHEPS);
  4462. -    }
  4463. -
  4464. -    /* orthogonality check */
  4465. -    mmtr_mlt(Q,Q,D);
  4466. -    for ( i = 0; i < D->m; i++ )
  4467. -    m_set_val(D,i,i,m_entry(D,i,i)-1.0);
  4468. -    if ( m_norm1(D) >= MACHEPS*m_norm1(Q)*m_norm_inf(Q)*10 )
  4469. -    {
  4470. -    errmesg("schur()");
  4471. -    printf("# Schur orthogonality error = %g [cf MACHEPS = %g]\n",
  4472. -           m_norm1(D), MACHEPS);
  4473. -    }
  4474. -
  4475. -    MEMCHK();
  4476. -
  4477. -    /* check for termination */
  4478. -    Atmp = m_get(2,2);
  4479. -    Qtmp = m_get(2,2);
  4480. -    /* this is a 2 x 2 matrix with real eigenvalues */
  4481. -    Atmp->me[0][0] = 1;
  4482. -    Atmp->me[1][1] = 1;
  4483. -    Atmp->me[0][1] = 4;
  4484. -    Atmp->me[1][0] = 1;
  4485. -    schur(Atmp,Qtmp);
  4486. -
  4487. -    MEMCHK();
  4488. -
  4489. -    /* now test SVD */
  4490. -    A = m_resize(A,11,7);
  4491. -    m_rand(A);
  4492. -    U = m_get(A->n,A->n);
  4493. -    Q = m_resize(Q,A->m,A->m);
  4494. -    u = v_resize(u,max(A->m,A->n));
  4495. -    svd(A,Q,U,u);
  4496. -    /* check reconstruction of A */
  4497. -    D = m_resize(D,A->m,A->n);
  4498. -    C = m_resize(C,A->m,A->n);
  4499. -    m_zero(D);
  4500. -    for ( i = 0; i < min(A->m,A->n); i++ )
  4501. -    m_set_val(D,i,i,v_entry(u,i));
  4502. -    mtrm_mlt(Q,D,C);
  4503. -    m_mlt(C,U,D);
  4504. -    m_sub(A,D,D);
  4505. -    if ( m_norm1(D) >= MACHEPS*m_norm1(U)*m_norm_inf(Q)*m_norm1(A) )
  4506. -    {
  4507. -    errmesg("svd()");
  4508. -    printf("# SVD reconstruction error = %g [cf MACHEPS = %g]\n",
  4509. -           m_norm1(D), MACHEPS);
  4510. -    }
  4511. -    /* check orthogonality of Q and U */
  4512. -    D = m_resize(D,Q->n,Q->n);
  4513. -    mtrm_mlt(Q,Q,D);
  4514. -    for ( i = 0; i < D->m; i++ )
  4515. -    m_set_val(D,i,i,m_entry(D,i,i)-1.0);
  4516. -    if ( m_norm1(D) >= MACHEPS*m_norm1(Q)*m_norm_inf(Q)*5 )
  4517. -    {
  4518. -    errmesg("svd()");
  4519. -    printf("# SVD orthognality error (Q) = %g [cf MACHEPS = %g\n",
  4520. -           m_norm1(D), MACHEPS);
  4521. -    }
  4522. -    D = m_resize(D,U->n,U->n);
  4523. -    mtrm_mlt(U,U,D);
  4524. -    for ( i = 0; i < D->m; i++ )
  4525. -    m_set_val(D,i,i,m_entry(D,i,i)-1.0);
  4526. -    if ( m_norm1(D) >= MACHEPS*m_norm1(U)*m_norm_inf(U)*5 )
  4527. -    {
  4528. -    errmesg("svd()");
  4529. -    printf("# SVD orthognality error (U) = %g [cf MACHEPS = %g\n",
  4530. -           m_norm1(D), MACHEPS);
  4531. -    }
  4532. -    for ( i = 0; i < u->dim; i++ )
  4533. -    if ( v_entry(u,i) < 0 || (i < u->dim-1 &&
  4534. -                  v_entry(u,i+1) > v_entry(u,i)) )
  4535. -        break;
  4536. -    if ( i < u->dim )
  4537. -    {
  4538. -    errmesg("svd()");
  4539. -    printf("# SVD sorting error\n");
  4540. -    }
  4541. -
  4542. -
  4543. -    /* test of long vectors */
  4544. -    notice("Long vectors");
  4545. -    x = v_resize(x,100000);
  4546. -    y = v_resize(y,100000);
  4547. -    z = v_resize(z,100000);
  4548. -    v_rand(x);
  4549. -    v_rand(y);
  4550. -    v_mltadd(x,y,3.0,z);
  4551. -    sv_mlt(1.0/3.0,z,z);
  4552. -    v_mltadd(z,x,-1.0/3.0,z);
  4553. -    v_sub(z,y,x);
  4554. -    if (v_norm2(x) >= MACHEPS*(x->dim)) {
  4555. -       errmesg("long vectors");
  4556. -       printf(" norm = %g\n",v_norm2(x));
  4557. -    }
  4558. -
  4559. -    mem_stat_free(1);
  4560. -
  4561. -    MEMCHK();
  4562. -
  4563. -    /**************************************************
  4564. -    VEC        *x, *y, *z, *u, *v, *w;
  4565. -    VEC        *diag, *beta;
  4566. -    PERM    *pi1, *pi2, *pi3, *pivot, *blocks;
  4567. -    MAT        *A, *B, *C, *D, *Q, *U;
  4568. -    **************************************************/
  4569. -    V_FREE(x);        V_FREE(y);    V_FREE(z);
  4570. -    V_FREE(u);        V_FREE(v);    V_FREE(w);
  4571. -    V_FREE(diag);    V_FREE(beta);
  4572. -    PX_FREE(pi1);    PX_FREE(pi2);    PX_FREE(pi3);
  4573. -    PX_FREE(pivot);    PX_FREE(blocks);
  4574. -    M_FREE(A);        M_FREE(B);    M_FREE(C);
  4575. -    M_FREE(D);        M_FREE(Q);    M_FREE(U);
  4576. -    M_FREE(Atmp);    M_FREE(Qtmp);
  4577. -
  4578. -    MEMCHK();
  4579. -    printf("# Finished torture test\n");
  4580. -    mem_info();
  4581. -
  4582. -    return 0;
  4583. -}
  4584. -
  4585. //GO.SYSIN DD torture.c
  4586. echo sptort.c 1>&2
  4587. sed >sptort.c <<'//GO.SYSIN DD sptort.c' 's/^-//'
  4588. -
  4589. -/**************************************************************************
  4590. -**
  4591. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  4592. -**
  4593. -**                 Meschach Library
  4594. -** 
  4595. -** This Meschach Library is provided "as is" without any express 
  4596. -** or implied warranty of any kind with respect to this software. 
  4597. -** In particular the authors shall not be liable for any direct, 
  4598. -** indirect, special, incidental or consequential damages arising 
  4599. -** in any way from use of the software.
  4600. -** 
  4601. -** Everyone is granted permission to copy, modify and redistribute this
  4602. -** Meschach Library, provided:
  4603. -**  1.  All copies contain this copyright notice.
  4604. -**  2.  All modified copies shall carry a notice stating who
  4605. -**      made the last modification and the date of such modification.
  4606. -**  3.  No charge is made for this software or works derived from it.  
  4607. -**      This clause shall not be construed as constraining other software
  4608. -**      distributed on the same medium as this software, nor is a
  4609. -**      distribution fee considered a charge.
  4610. -**
  4611. -***************************************************************************/
  4612. -
  4613. -
  4614. -/*
  4615. -    This file contains tests for the sparse matrix part of Meschach
  4616. -*/
  4617. -
  4618. -#include    <stdio.h>
  4619. -#include    <math.h>
  4620. -#include    "matrix2.h"
  4621. -#include    "sparse2.h"
  4622. -#include        "iter.h"
  4623. -
  4624. -#define    errmesg(mesg)    printf("Error: %s error: line %d\n",mesg,__LINE__)
  4625. -#define notice(mesg)    printf("# Testing %s...\n",mesg);
  4626. -
  4627. -/* for iterative methods */
  4628. -
  4629. -#if REAL == DOUBLE
  4630. -#define    EPS    1e-7
  4631. -#elif REAL == FLOAT
  4632. -#define EPS   1e-3
  4633. -#endif
  4634. -
  4635. -int    chk_col_access(A)
  4636. -SPMAT    *A;
  4637. -{
  4638. -    int        i, j, nxt_idx, nxt_row, scan_cnt, total_cnt;
  4639. -    SPROW    *r;
  4640. -    row_elt    *e;
  4641. -
  4642. -    if ( ! A )
  4643. -    error(E_NULL,"chk_col_access");
  4644. -    if ( ! A->flag_col )
  4645. -    return FALSE;
  4646. -
  4647. -    /* scan down each column, counting the number of entries met */
  4648. -    scan_cnt = 0;
  4649. -    for ( j = 0; j < A->n; j++ )
  4650. -    {
  4651. -    i = -1;
  4652. -    nxt_idx = A->start_idx[j];
  4653. -    nxt_row = A->start_row[j];
  4654. -    while ( nxt_row >= 0 && nxt_idx >= 0 && nxt_row > i )
  4655. -    {
  4656. -        i = nxt_row;
  4657. -        r = &(A->row[i]);
  4658. -        e = &(r->elt[nxt_idx]);
  4659. -        nxt_idx = e->nxt_idx;
  4660. -        nxt_row = e->nxt_row;
  4661. -        scan_cnt++;
  4662. -    }
  4663. -    }
  4664. -
  4665. -    total_cnt = 0;
  4666. -    for ( i = 0; i < A->m; i++ )
  4667. -    total_cnt += A->row[i].len;
  4668. -    if ( total_cnt != scan_cnt )
  4669. -    return FALSE;
  4670. -    else
  4671. -    return TRUE;
  4672. -}
  4673. -
  4674. -
  4675. -void    main(argc, argv)
  4676. -int    argc;
  4677. -char    *argv[];
  4678. -{
  4679. -    VEC        *x, *y, *z, *u, *v;
  4680. -    Real    s1, s2;
  4681. -    PERM    *pivot;
  4682. -    SPMAT    *A, *B, *C;
  4683. -    SPMAT       *B1, *C1;
  4684. -    SPROW    *r;
  4685. -    int        i, j, k, deg, seed, m, m_old, n, n_old;
  4686. -
  4687. -
  4688. -    mem_info_on(TRUE);
  4689. -
  4690. -    setbuf(stdout, (char *)NULL);
  4691. -    /* get seed if in argument list */
  4692. -    if ( argc == 1 )
  4693. -    seed = 1111;
  4694. -    else if ( argc == 2 && sscanf(argv[1],"%d",&seed) == 1 )
  4695. -    ;
  4696. -    else
  4697. -    {
  4698. -    printf("usage: %s [seed]\n", argv[0]);
  4699. -    exit(0);
  4700. -    }
  4701. -    srand(seed);
  4702. -
  4703. -    /* set up two random sparse matrices */
  4704. -    m = 120;
  4705. -    n = 100;
  4706. -    deg = 8;
  4707. -    notice("allocating sparse matrices");
  4708. -    A = sp_get(m,n,deg);
  4709. -    B = sp_get(m,n,deg);
  4710. -    notice("setting and getting matrix entries");
  4711. -    for ( k = 0; k < m*deg; k++ )
  4712. -    {
  4713. -    i = (rand() >> 8) % m;
  4714. -    j = (rand() >> 8) % n;
  4715. -    sp_set_val(A,i,j,rand()/((Real)MAX_RAND));
  4716. -    i = (rand() >> 8) % m;
  4717. -    j = (rand() >> 8) % n;
  4718. -    sp_set_val(B,i,j,rand()/((Real)MAX_RAND));
  4719. -    }
  4720. -    for ( k = 0; k < 10; k++ )
  4721. -    {
  4722. -    s1 = rand()/((Real)MAX_RAND);
  4723. -    i = (rand() >> 8) % m;
  4724. -    j = (rand() >> 8) % n;
  4725. -    sp_set_val(A,i,j,s1);
  4726. -    s2 = sp_get_val(A,i,j);
  4727. -    if ( fabs(s1 - s2) >= MACHEPS )
  4728. -        break;
  4729. -    }
  4730. -    if ( k < 10 )
  4731. -    errmesg("sp_set_val()/sp_get_val()");
  4732. -
  4733. -    /* test copy routines */
  4734. -    notice("copy routines");
  4735. -    x = v_get(n);
  4736. -    y = v_get(m);
  4737. -    z = v_get(m);
  4738. -    /* first copy routine */
  4739. -    C = sp_copy(A);
  4740. -    for ( k = 0; k < 100; k++ )
  4741. -    {
  4742. -    v_rand(x);
  4743. -    sp_mv_mlt(A,x,y);
  4744. -    sp_mv_mlt(C,x,z);
  4745. -    if ( v_norm_inf(v_sub(y,z,z)) >= MACHEPS*deg*m )
  4746. -        break;
  4747. -    }
  4748. -    if ( k < 100 )
  4749. -    {
  4750. -    errmesg("sp_copy()/sp_mv_mlt()");
  4751. -    printf("# Error in A.x (inf norm) = %g [cf MACHEPS = %g]\n",
  4752. -           v_norm_inf(z), MACHEPS);
  4753. -    }
  4754. -    /* second copy routine
  4755. -       -- note that A & B have different sparsity patterns */
  4756. -
  4757. -    mem_stat_mark(1);
  4758. -    sp_copy2(A,B);
  4759. -    mem_stat_free(1);
  4760. -    for ( k = 0; k < 10; k++ )
  4761. -    {
  4762. -    v_rand(x);
  4763. -    sp_mv_mlt(A,x,y);
  4764. -    sp_mv_mlt(B,x,z);
  4765. -    if ( v_norm_inf(v_sub(y,z,z)) >= MACHEPS*deg*m )
  4766. -        break;
  4767. -    }
  4768. -    if ( k < 10 )
  4769. -    {
  4770. -    errmesg("sp_copy2()/sp_mv_mlt()");
  4771. -    printf("# Error in A.x (inf norm) = %g [cf MACHEPS = %g]\n",
  4772. -           v_norm_inf(z), MACHEPS);
  4773. -    }
  4774. -
  4775. -    /* now check compacting routine */
  4776. -    notice("compacting routine");
  4777. -    sp_compact(B,0.0);
  4778. -    for ( k = 0; k < 10; k++ )
  4779. -    {
  4780. -    v_rand(x);
  4781. -    sp_mv_mlt(A,x,y);
  4782. -    sp_mv_mlt(B,x,z);
  4783. -    if ( v_norm_inf(v_sub(y,z,z)) >= MACHEPS*deg*m )
  4784. -        break;
  4785. -    }
  4786. -    if ( k < 10 )
  4787. -    {
  4788. -    errmesg("sp_compact()");
  4789. -    printf("# Error in A.x (inf norm) = %g [cf MACHEPS = %g]\n",
  4790. -           v_norm_inf(z), MACHEPS);
  4791. -    }
  4792. -    for ( i = 0; i < B->m; i++ )
  4793. -    {
  4794. -    r = &(B->row[i]);
  4795. -    for ( j = 0; j < r->len; j++ )
  4796. -        if ( r->elt[j].val == 0.0 )
  4797. -        break;
  4798. -    }
  4799. -    if ( i < B->m )
  4800. -    {
  4801. -    errmesg("sp_compact()");
  4802. -    printf("# Zero entry in compacted matrix\n");
  4803. -    }
  4804. -
  4805. -    /* check column access paths */
  4806. -    notice("resizing and access paths");
  4807. -    m_old = A->m-1;
  4808. -    n_old = A->n-1;
  4809. -    A = sp_resize(A,A->m+10,A->n+10);
  4810. -    for ( k = 0 ; k < 20; k++ )
  4811. -    {
  4812. -    i = m_old + ((rand() >> 8) % 10);
  4813. -    j = n_old + ((rand() >> 8) % 10);
  4814. -    s1 = rand()/((Real)MAX_RAND);
  4815. -    sp_set_val(A,i,j,s1);
  4816. -    if ( fabs(s1 - sp_get_val(A,i,j)) >= MACHEPS )
  4817. -        break;
  4818. -    }
  4819. -    if ( k < 20 )
  4820. -    errmesg("sp_resize()");
  4821. -    sp_col_access(A);
  4822. -    if ( ! chk_col_access(A) )
  4823. -    {
  4824. -    errmesg("sp_col_access()");
  4825. -    }
  4826. -    sp_diag_access(A);
  4827. -    for ( i = 0; i < A->m; i++ )
  4828. -    {
  4829. -    r = &(A->row[i]);
  4830. -    if ( r->diag != sprow_idx(r,i) )
  4831. -        break;
  4832. -    }
  4833. -    if ( i < A->m )
  4834. -    {
  4835. -    errmesg("sp_diag_access()");
  4836. -    }
  4837. -
  4838. -    /* test both sp_mv_mlt() and sp_vm_mlt() */
  4839. -    x = v_resize(x,B->n);
  4840. -    y = v_resize(y,B->m);
  4841. -    u = v_get(B->m);
  4842. -    v = v_get(B->n);
  4843. -    for ( k = 0; k < 10; k++ )
  4844. -    {
  4845. -    v_rand(x);
  4846. -    v_rand(y);
  4847. -    sp_mv_mlt(B,x,u);
  4848. -    sp_vm_mlt(B,y,v);
  4849. -    if ( fabs(in_prod(x,v) - in_prod(y,u)) >=
  4850. -        MACHEPS*v_norm2(x)*v_norm2(u)*5 )
  4851. -        break;
  4852. -    }
  4853. -    if ( k < 10 )
  4854. -    {
  4855. -    errmesg("sp_mv_mlt()/sp_vm_mlt()");
  4856. -    printf("# Error in inner products = %g [cf MACHEPS = %g]\n",
  4857. -           fabs(in_prod(x,v) - in_prod(y,u)), MACHEPS);
  4858. -    }
  4859. -
  4860. -    SP_FREE(A);
  4861. -    SP_FREE(B);
  4862. -    SP_FREE(C);
  4863. -
  4864. -    /* now test Cholesky and LU factorise and solve */
  4865. -    notice("sparse Cholesky factorise/solve");
  4866. -    A = iter_gen_sym(120,8);
  4867. -    B = sp_copy(A);
  4868. -    spCHfactor(A);
  4869. -    x = v_resize(x,A->m);
  4870. -    y = v_resize(y,A->m);
  4871. -    v_rand(x);
  4872. -    sp_mv_mlt(B,x,y);
  4873. -    z = v_resize(z,A->m);
  4874. -    spCHsolve(A,y,z);
  4875. -    v = v_resize(v,A->m);
  4876. -    sp_mv_mlt(B,z,v);
  4877. -    /* compute residual */
  4878. -    v_sub(y,v,v);
  4879. -    if ( v_norm2(v) >= MACHEPS*v_norm2(y)*10 )
  4880. -    {
  4881. -    errmesg("spCHfactor()/spCHsolve()");
  4882. -    printf("# Sparse Cholesky residual = %g [cf MACHEPS = %g]\n",
  4883. -           v_norm2(v), MACHEPS);
  4884. -    }
  4885. -    /* compute error in solution */
  4886. -    v_sub(x,z,z);
  4887. -    if ( v_norm2(z) > MACHEPS*v_norm2(x)*10 )
  4888. -    {
  4889. -    errmesg("spCHfactor()/spCHsolve()");
  4890. -    printf("# Solution error = %g [cf MACHEPS = %g]\n",
  4891. -           v_norm2(z), MACHEPS);
  4892. -    }
  4893. -
  4894. -    /* now test symbolic and incomplete factorisation */
  4895. -    SP_FREE(A);
  4896. -    A = sp_copy(B);
  4897. -    
  4898. -    mem_stat_mark(2);
  4899. -    spCHsymb(A);
  4900. -    mem_stat_mark(2);
  4901. -
  4902. -    spICHfactor(A);
  4903. -    spCHsolve(A,y,z);
  4904. -    v = v_resize(v,A->m);
  4905. -    sp_mv_mlt(B,z,v);
  4906. -    /* compute residual */
  4907. -    v_sub(y,v,v);
  4908. -    if ( v_norm2(v) >= MACHEPS*v_norm2(y)*5 )
  4909. -    {
  4910. -    errmesg("spCHsymb()/spICHfactor()");
  4911. -    printf("# Sparse Cholesky residual = %g [cf MACHEPS = %g]\n",
  4912. -           v_norm2(v), MACHEPS);
  4913. -    }
  4914. -    /* compute error in solution */
  4915. -    v_sub(x,z,z);
  4916. -    if ( v_norm2(z) > MACHEPS*v_norm2(x)*10 )
  4917. -    {
  4918. -    errmesg("spCHsymb()/spICHfactor()");
  4919. -    printf("# Solution error = %g [cf MACHEPS = %g]\n",
  4920. -           v_norm2(z), MACHEPS);
  4921. -    }
  4922. -
  4923. -    /* now test sparse LU factorisation */
  4924. -    notice("sparse LU factorise/solve");
  4925. -    SP_FREE(A);
  4926. -    SP_FREE(B);
  4927. -    A = iter_gen_nonsym(100,100,8,1.0);
  4928. -
  4929. -    B = sp_copy(A);
  4930. -    x = v_resize(x,A->n);
  4931. -    z = v_resize(z,A->n);
  4932. -    y = v_resize(y,A->m);
  4933. -    v = v_resize(v,A->m);
  4934. -
  4935. -    v_rand(x);
  4936. -    sp_mv_mlt(B,x,y);
  4937. -    pivot = px_get(A->m);
  4938. -
  4939. -    mem_stat_mark(3);
  4940. -    spLUfactor(A,pivot,0.1);
  4941. -    spLUsolve(A,pivot,y,z);
  4942. -    mem_stat_free(3);
  4943. -    sp_mv_mlt(B,z,v);
  4944. -
  4945. -    /* compute residual */
  4946. -    v_sub(y,v,v);
  4947. -    if ( v_norm2(v) >= MACHEPS*v_norm2(y)*A->m )
  4948. -    {
  4949. -    errmesg("spLUfactor()/spLUsolve()");
  4950. -    printf("# Sparse LU residual = %g [cf MACHEPS = %g]\n",
  4951. -           v_norm2(v), MACHEPS);
  4952. -    }
  4953. -    /* compute error in solution */
  4954. -    v_sub(x,z,z);
  4955. -    if ( v_norm2(z) > MACHEPS*v_norm2(x)*100*A->m )
  4956. -    {
  4957. -    errmesg("spLUfactor()/spLUsolve()");
  4958. -    printf("# Sparse LU solution error = %g [cf MACHEPS = %g]\n",
  4959. -           v_norm2(z), MACHEPS);
  4960. -    }
  4961. -
  4962. -    /* now check spLUTsolve */
  4963. -    mem_stat_mark(4);
  4964. -    sp_vm_mlt(B,x,y);
  4965. -    spLUTsolve(A,pivot,y,z);
  4966. -    sp_vm_mlt(B,z,v);
  4967. -    mem_stat_free(4);
  4968. -
  4969. -    /* compute residual */
  4970. -    v_sub(y,v,v);
  4971. -    if ( v_norm2(v) >= MACHEPS*v_norm2(y)*A->m )
  4972. -    {
  4973. -    errmesg("spLUTsolve()");
  4974. -    printf("# Sparse LU residual = %g [cf MACHEPS = %g]\n",
  4975. -           v_norm2(v), MACHEPS);
  4976. -    }
  4977. -    /* compute error in solution */
  4978. -    v_sub(x,z,z);
  4979. -    if ( v_norm2(z) > MACHEPS*v_norm2(x)*100*A->m )
  4980. -    {
  4981. -    errmesg("spLUTsolve()");
  4982. -    printf("# Sparse LU solution error = %g [cf MACHEPS = %g]\n",
  4983. -           v_norm2(z), MACHEPS);
  4984. -    }
  4985. -
  4986. -    /* algebraic operations */
  4987. -    notice("addition,subtraction and multiplying by a number");
  4988. -    SP_FREE(A);
  4989. -    SP_FREE(B);
  4990. -
  4991. -    m = 120;
  4992. -    n = 120;
  4993. -    deg = 5;
  4994. -    A = sp_get(m,n,deg);
  4995. -    B = sp_get(m,n,deg);
  4996. -    C = sp_get(m,n,deg);
  4997. -    C1 = sp_get(m,n,deg);
  4998. -
  4999. -    for ( k = 0; k < m*deg; k++ )
  5000. -    {
  5001. -    i = (rand() >> 8) % m;
  5002. -    j = (rand() >> 8) % n;
  5003. -    sp_set_val(A,i,j,rand()/((Real)MAX_RAND));
  5004. -    i = (rand() >> 8) % m;
  5005. -    j = (rand() >> 8) % n;
  5006. -    sp_set_val(B,i,j,rand()/((Real)MAX_RAND));
  5007. -    }
  5008. -    
  5009. -    s1 = mrand(); 
  5010. -    B1 = sp_copy(B);
  5011. -
  5012. -    mem_stat_mark(1);
  5013. -    sp_smlt(B,s1,C);
  5014. -    sp_add(A,C,C1);
  5015. -    sp_sub(C1,A,C);
  5016. -    sp_smlt(C,-1.0/s1,C);
  5017. -    sp_add(C,B1,C);
  5018. -
  5019. -    s2 = 0.0;
  5020. -    for (k=0; k < C->m; k++) {
  5021. -       r = &(C->row[k]);
  5022. -       for (j=0; j < r->len; j++) {
  5023. -      if (s2 < fabs(r->elt[j].val)) 
  5024. -        s2 = fabs(r->elt[j].val);
  5025. -       }
  5026. -    }
  5027. -
  5028. -    if (s2 > MACHEPS*A->m) {
  5029. -       errmesg("add, sub, mlt sparse matrices (args not in situ)\n");
  5030. -       printf(" difference = %g [MACEPS = %g]\n",s2,MACHEPS);
  5031. -    }
  5032. -
  5033. -    sp_mltadd(A,B1,s1,C1);
  5034. -    sp_sub(C1,A,A);
  5035. -    sp_smlt(A,1.0/s1,C1);
  5036. -    sp_sub(C1,B1,C1);
  5037. -    mem_stat_free(1);
  5038. -
  5039. -    s2 = 0.0;
  5040. -    for (k=0; k < C1->m; k++) {
  5041. -       r = &(C1->row[k]);
  5042. -       for (j=0; j < r->len; j++) {
  5043. -      if (s2 < fabs(r->elt[j].val)) 
  5044. -        s2 = fabs(r->elt[j].val);
  5045. -       }
  5046. -    }
  5047. -
  5048. -    if (s2 > MACHEPS*A->m) {
  5049. -       errmesg("add, sub, mlt sparse matrices (args not in situ)\n");
  5050. -       printf(" difference = %g [MACEPS = %g]\n",s2,MACHEPS);
  5051. -    }
  5052. -
  5053. -    V_FREE(x);
  5054. -    V_FREE(y);    
  5055. -    V_FREE(z);
  5056. -    V_FREE(u);
  5057. -    V_FREE(v);  
  5058. -    PX_FREE(pivot);
  5059. -    SP_FREE(A);
  5060. -    SP_FREE(B);
  5061. -    SP_FREE(C);
  5062. -    SP_FREE(B1);
  5063. -    SP_FREE(C1);
  5064. -
  5065. -    printf("# Done testing (%s)\n",argv[0]);
  5066. -    mem_info();
  5067. -}
  5068. -    
  5069. -
  5070. -
  5071. -
  5072. -
  5073. //GO.SYSIN DD sptort.c
  5074. echo ztorture.c 1>&2
  5075. sed >ztorture.c <<'//GO.SYSIN DD ztorture.c' 's/^-//'
  5076. -
  5077. -/**************************************************************************
  5078. -**
  5079. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  5080. -**
  5081. -**                 Meschach Library
  5082. -** 
  5083. -** This Meschach Library is provided "as is" without any express 
  5084. -** or implied warranty of any kind with respect to this software. 
  5085. -** In particular the authors shall not be liable for any direct, 
  5086. -** indirect, special, incidental or consequential damages arising 
  5087. -** in any way from use of the software.
  5088. -** 
  5089. -** Everyone is granted permission to copy, modify and redistribute this
  5090. -** Meschach Library, provided:
  5091. -**  1.  All copies contain this copyright notice.
  5092. -**  2.  All modified copies shall carry a notice stating who
  5093. -**      made the last modification and the date of such modification.
  5094. -**  3.  No charge is made for this software or works derived from it.  
  5095. -**      This clause shall not be construed as constraining other software
  5096. -**      distributed on the same medium as this software, nor is a
  5097. -**      distribution fee considered a charge.
  5098. -**
  5099. -***************************************************************************/
  5100. -
  5101. -
  5102. -/*
  5103. -    This file contains a series of tests for the Meschach matrix
  5104. -    library, complex routines
  5105. -*/
  5106. -
  5107. -static char rcsid[] = "$Id: $";
  5108. -
  5109. -#include    <stdio.h>
  5110. -#include    <math.h>
  5111. -#include     "zmatrix2.h"
  5112. -#include        "matlab.h"
  5113. -
  5114. -
  5115. -#define    errmesg(mesg)    printf("Error: %s error: line %d\n",mesg,__LINE__)
  5116. -#define notice(mesg)    printf("# Testing %s...\n",mesg);
  5117. -
  5118. -/* extern    int    malloc_chain_check(); */
  5119. -/* #define MEMCHK() if ( malloc_chain_check(0) ) \
  5120. -{ printf("Error in malloc chain: \"%s\", line %d\n", \
  5121. -     __FILE__, __LINE__); exit(0); } */
  5122. -#define    MEMCHK() 
  5123. -
  5124. -/* cmp_perm -- returns 1 if pi1 == pi2, 0 otherwise */
  5125. -int    cmp_perm(pi1, pi2)
  5126. -PERM    *pi1, *pi2;
  5127. -{
  5128. -    int        i;
  5129. -
  5130. -    if ( ! pi1 || ! pi2 )
  5131. -    error(E_NULL,"cmp_perm");
  5132. -    if ( pi1->size != pi2->size )
  5133. -    return 0;
  5134. -    for ( i = 0; i < pi1->size; i++ )
  5135. -    if ( pi1->pe[i] != pi2->pe[i] )
  5136. -        return 0;
  5137. -    return 1;
  5138. -}
  5139. -
  5140. -/* px_rand -- generates sort-of random permutation */
  5141. -PERM    *px_rand(pi)
  5142. -PERM    *pi;
  5143. -{
  5144. -    int        i, j, k;
  5145. -
  5146. -    if ( ! pi )
  5147. -    error(E_NULL,"px_rand");
  5148. -
  5149. -    for ( i = 0; i < 3*pi->size; i++ )
  5150. -    {
  5151. -    j = (rand() >> 8) % pi->size;
  5152. -    k = (rand() >> 8) % pi->size;
  5153. -    px_transp(pi,j,k);
  5154. -    }
  5155. -
  5156. -    return pi;
  5157. -}
  5158. -
  5159. -#define    SAVE_FILE    "asx5213a.mat"
  5160. -#define    MATLAB_NAME    "alpha"
  5161. -char    name[81] = MATLAB_NAME;
  5162. -
  5163. -void    main(argc, argv)
  5164. -int    argc;
  5165. -char    *argv[];
  5166. -{
  5167. -    ZVEC     *x = ZVNULL, *y = ZVNULL, *z = ZVNULL, *u = ZVNULL;
  5168. -    ZVEC    *diag = ZVNULL;
  5169. -    PERM    *pi1 = PNULL, *pi2 = PNULL, *pivot = PNULL;
  5170. -    ZMAT    *A = ZMNULL, *B = ZMNULL, *C = ZMNULL, *D = ZMNULL,
  5171. -    *Q = ZMNULL;
  5172. -    complex    ONE;
  5173. -    complex    z1, z2, z3;
  5174. -    Real    cond_est, s1, s2, s3;
  5175. -    int        i, seed;
  5176. -    FILE    *fp;
  5177. -    char    *cp;
  5178. -
  5179. -
  5180. -    mem_info_on(TRUE);
  5181. -
  5182. -    setbuf(stdout,(char *)NULL);
  5183. -
  5184. -    seed = 1111;
  5185. -    if ( argc > 2 )
  5186. -    {
  5187. -    printf("usage: %s [seed]\n",argv[0]);
  5188. -    exit(0);
  5189. -    }
  5190. -    else if ( argc == 2 )
  5191. -    sscanf(argv[1], "%d", &seed);
  5192. -
  5193. -    /* set seed for rand() */
  5194. -    smrand(seed);
  5195. -
  5196. -    /* print out version information */
  5197. -    m_version();
  5198. -
  5199. -    printf("# Meschach Complex numbers & vectors torture test\n\n");
  5200. -    printf("# grep \"^Error\" the output for a listing of errors\n");
  5201. -    printf("# Don't panic if you see \"Error\" appearing; \n");
  5202. -    printf("# Also check the reported size of error\n");
  5203. -    printf("# This program uses randomly generated problems and therefore\n");
  5204. -    printf("# may occasionally produce ill-conditioned problems\n");
  5205. -    printf("# Therefore check the size of the error compared with MACHEPS\n");
  5206. -    printf("# If the error is within 1000*MACHEPS then don't worry\n");
  5207. -    printf("# If you get an error of size 0.1 or larger there is \n");
  5208. -    printf("# probably a bug in the code or the compilation procedure\n\n");
  5209. -    printf("# seed = %d\n",seed);
  5210. -
  5211. -    printf("\n");
  5212. -
  5213. -    mem_stat_mark(1);
  5214. -
  5215. -    notice("complex arithmetic & special functions");
  5216. -
  5217. -    ONE = zmake(1.0,0.0);
  5218. -    printf("# ONE = ");    z_output(ONE);
  5219. -    z1.re = mrand();    z1.im = mrand();
  5220. -    z2.re = mrand();    z2.im = mrand();
  5221. -    z3 = zadd(z1,z2);
  5222. -    if ( fabs(z1.re+z2.re-z3.re) + fabs(z1.im+z2.im-z3.im) > 10*MACHEPS )
  5223. -    errmesg("zadd");
  5224. -    z3 = zsub(z1,z2);
  5225. -    if ( fabs(z1.re-z2.re-z3.re) + fabs(z1.im-z2.im-z3.im) > 10*MACHEPS )
  5226. -    errmesg("zadd");
  5227. -    z3 = zmlt(z1,z2);
  5228. -    if ( fabs(z1.re*z2.re - z1.im*z2.im - z3.re) +
  5229. -     fabs(z1.im*z2.re + z1.re*z2.im - z3.im) > 10*MACHEPS )
  5230. -    errmesg("zmlt");
  5231. -    s1 = zabs(z1);
  5232. -    if ( fabs(s1*s1 - (z1.re*z1.re+z1.im*z1.im)) > 10*MACHEPS )
  5233. -    errmesg("zabs");
  5234. -    if ( zabs(zsub(z1,zmlt(z2,zdiv(z1,z2)))) > 10*MACHEPS ||
  5235. -     zabs(zsub(ONE,zdiv(z1,zmlt(z2,zdiv(z1,z2))))) > 10*MACHEPS )
  5236. -    errmesg("zdiv");
  5237. -
  5238. -    z3 = zsqrt(z1);
  5239. -    if ( zabs(zsub(z1,zmlt(z3,z3))) > 10*MACHEPS )
  5240. -    errmesg("zsqrt");
  5241. -    if ( zabs(zsub(z1,zlog(zexp(z1)))) > 10*MACHEPS )
  5242. -    errmesg("zexp/zlog");
  5243. -    
  5244. -
  5245. -    printf("# Check: MACHEPS = %g\n",MACHEPS);
  5246. -    /* allocate, initialise, copy and resize operations */
  5247. -    /* ZVEC */
  5248. -    notice("vector initialise, copy & resize");
  5249. -    x = zv_get(12);
  5250. -    y = zv_get(15);
  5251. -    z = zv_get(12);
  5252. -    zv_rand(x);
  5253. -    zv_rand(y);
  5254. -    z = zv_copy(x,z);
  5255. -    if ( zv_norm2(zv_sub(x,z,z)) >= MACHEPS )
  5256. -    errmesg("ZVEC copy");
  5257. -    zv_copy(x,y);
  5258. -    x = zv_resize(x,10);
  5259. -    y = zv_resize(y,10);
  5260. -    if ( zv_norm2(zv_sub(x,y,z)) >= MACHEPS )
  5261. -    errmesg("ZVEC copy/resize");
  5262. -    x = zv_resize(x,15);
  5263. -    y = zv_resize(y,15);
  5264. -    if ( zv_norm2(zv_sub(x,y,z)) >= MACHEPS )
  5265. -    errmesg("VZEC resize");
  5266. -
  5267. -    /* ZMAT */
  5268. -    notice("matrix initialise, copy & resize");
  5269. -    A = zm_get(8,5);
  5270. -    B = zm_get(3,9);
  5271. -    C = zm_get(8,5);
  5272. -    zm_rand(A);
  5273. -    zm_rand(B);
  5274. -    C = zm_copy(A,C);
  5275. -    if ( zm_norm_inf(zm_sub(A,C,C)) >= MACHEPS )
  5276. -    errmesg("ZMAT copy");
  5277. -    zm_copy(A,B);
  5278. -    A = zm_resize(A,3,5);
  5279. -    B = zm_resize(B,3,5);
  5280. -    if ( zm_norm_inf(zm_sub(A,B,C)) >= MACHEPS )
  5281. -    errmesg("ZMAT copy/resize");
  5282. -    A = zm_resize(A,10,10);
  5283. -    B = zm_resize(B,10,10);
  5284. -    if ( zm_norm_inf(zm_sub(A,B,C)) >= MACHEPS )
  5285. -    errmesg("ZMAT resize");
  5286. -
  5287. -    MEMCHK();
  5288. -
  5289. -    /* PERM */
  5290. -    notice("permutation initialise, inverting & permuting vectors");
  5291. -    pi1 = px_get(15);
  5292. -    pi2 = px_get(12);
  5293. -    px_rand(pi1);
  5294. -    zv_rand(x);
  5295. -    px_zvec(pi1,x,z);
  5296. -    y = zv_resize(y,x->dim);
  5297. -    pxinv_zvec(pi1,z,y);
  5298. -    if ( zv_norm2(zv_sub(x,y,z)) >= MACHEPS )
  5299. -    errmesg("PERMute vector");
  5300. -
  5301. -    /* testing catch() etc */
  5302. -    notice("error handling routines");
  5303. -    catch(E_NULL,
  5304. -      catchall(zv_add(ZVNULL,ZVNULL,ZVNULL);
  5305. -             errmesg("tracecatch() failure"),
  5306. -             printf("# tracecatch() caught error\n");
  5307. -             error(E_NULL,"main"));
  5308. -                 errmesg("catch() failure"),
  5309. -      printf("# catch() caught E_NULL error\n"));
  5310. -
  5311. -    /* testing inner products and v_mltadd() etc */
  5312. -    notice("inner products and linear combinations");
  5313. -    u = zv_get(x->dim);
  5314. -    zv_rand(u);
  5315. -    zv_rand(x);
  5316. -    zv_resize(y,x->dim);
  5317. -    zv_rand(y);
  5318. -    zv_mltadd(y,x,zneg(zdiv(zin_prod(x,y),zin_prod(x,x))),z);
  5319. -    if ( zabs(zin_prod(x,z)) >= 5*MACHEPS*x->dim )
  5320. -    {
  5321. -    errmesg("zv_mltadd()/zin_prod()");
  5322. -    printf("# error norm = %g\n", zabs(zin_prod(x,z)));
  5323. -    }
  5324. -
  5325. -    z1 = zneg(zdiv(zin_prod(x,y),zmake(zv_norm2(x)*zv_norm2(x),0.0)));
  5326. -    zv_mlt(z1,x,u);
  5327. -    zv_add(y,u,u);
  5328. -    if ( zv_norm2(zv_sub(u,z,u)) >= MACHEPS*x->dim )
  5329. -    {
  5330. -    errmesg("zv_mlt()/zv_norm2()");
  5331. -    printf("# error norm = %g\n", zv_norm2(u));
  5332. -    }
  5333. -
  5334. -#ifdef ANSI_C
  5335. -    zv_linlist(u,x,z1,y,ONE,VNULL);
  5336. -    if ( zv_norm2(zv_sub(u,z,u)) >= MACHEPS*x->dim )
  5337. -    errmesg("zv_linlist()");
  5338. -#endif
  5339. -#ifdef VARARGS
  5340. -    zv_linlist(u,x,z1,y,ONE,VNULL);
  5341. -    if ( zv_norm2(zv_sub(u,z,u)) >= MACHEPS*x->dim )
  5342. -    errmesg("zv_linlist()");
  5343. -#endif
  5344. -
  5345. -    MEMCHK();
  5346. -
  5347. -    /* vector norms */
  5348. -    notice("vector norms");
  5349. -    x = zv_resize(x,12);
  5350. -    zv_rand(x);
  5351. -    for ( i = 0; i < x->dim; i++ )
  5352. -    if ( zabs(v_entry(x,i)) >= 0.7 )
  5353. -        v_set_val(x,i,ONE);
  5354. -        else
  5355. -        v_set_val(x,i,zneg(ONE));
  5356. -    s1 = zv_norm1(x);
  5357. -    s2 = zv_norm2(x);    
  5358. -    s3 = zv_norm_inf(x);
  5359. -    if ( fabs(s1 - x->dim) >= MACHEPS*x->dim ||
  5360. -     fabs(s2 - sqrt((double)(x->dim))) >= MACHEPS*x->dim ||
  5361. -     fabs(s3 - 1.0) >= MACHEPS )
  5362. -    errmesg("zv_norm1/2/_inf()");
  5363. -
  5364. -    /* test matrix multiply etc */
  5365. -    notice("matrix multiply and invert");
  5366. -    A = zm_resize(A,10,10);
  5367. -    B = zm_resize(B,10,10);
  5368. -    zm_rand(A);
  5369. -    zm_inverse(A,B);
  5370. -    zm_mlt(A,B,C);
  5371. -    for ( i = 0; i < C->m; i++ )
  5372. -    m_set_val(C,i,i,zsub(m_entry(C,i,i),ONE));
  5373. -    if ( zm_norm_inf(C) >= MACHEPS*zm_norm_inf(A)*zm_norm_inf(B)*5 )
  5374. -    errmesg("zm_inverse()/zm_mlt()");
  5375. -
  5376. -    MEMCHK();
  5377. -
  5378. -    /* ... and adjoints */
  5379. -    notice("adjoints and adjoint-multiplies");
  5380. -    zm_adjoint(A,A);    /* can do square matrices in situ */
  5381. -    zmam_mlt(A,B,C);
  5382. -    for ( i = 0; i < C->m; i++ )
  5383. -    m_set_val(C,i,i,zsub(m_entry(C,i,i),ONE));
  5384. -    if ( zm_norm_inf(C) >= MACHEPS*zm_norm_inf(A)*zm_norm_inf(B)*5 )
  5385. -    errmesg("zm_adjoint()/zmam_mlt()");
  5386. -    zm_adjoint(A,A);
  5387. -    zm_adjoint(B,B);
  5388. -    zmma_mlt(A,B,C);
  5389. -    for ( i = 0; i < C->m; i++ )
  5390. -    m_set_val(C,i,i,zsub(m_entry(C,i,i),ONE));
  5391. -    if ( zm_norm_inf(C) >= MACHEPS*zm_norm_inf(A)*zm_norm_inf(B)*5 )
  5392. -    errmesg("zm_adjoint()/zmma_mlt()");
  5393. -    zsm_mlt(zmake(3.71,2.753),B,B);
  5394. -    zmma_mlt(A,B,C);
  5395. -    for ( i = 0; i < C->m; i++ )
  5396. -    m_set_val(C,i,i,zsub(m_entry(C,i,i),zmake(3.71,-2.753)));
  5397. -    if ( zm_norm_inf(C) >= MACHEPS*zm_norm_inf(A)*zm_norm_inf(B)*5 )
  5398. -    errmesg("szm_mlt()/zmma_mlt()");
  5399. -    zm_adjoint(B,B);
  5400. -    zsm_mlt(zdiv(ONE,zmake(3.71,-2.753)),B,B);
  5401. -
  5402. -    MEMCHK();
  5403. -
  5404. -    /* ... and matrix-vector multiplies */
  5405. -    notice("matrix-vector multiplies");
  5406. -    x = zv_resize(x,A->n);
  5407. -    y = zv_resize(y,A->m);
  5408. -    z = zv_resize(z,A->m);
  5409. -    u = zv_resize(u,A->n);
  5410. -    zv_rand(x);
  5411. -    zv_rand(y);
  5412. -    zmv_mlt(A,x,z);
  5413. -    z1 = zin_prod(y,z);
  5414. -    zvm_mlt(A,y,u);
  5415. -    z2 = zin_prod(u,x);
  5416. -    if ( zabs(zsub(z1,z2)) >= (MACHEPS*x->dim)*x->dim )
  5417. -    {
  5418. -    errmesg("zmv_mlt()/zvm_mlt()");
  5419. -    printf("# difference between inner products is %g\n",
  5420. -           zabs(zsub(z1,z2)));
  5421. -    }
  5422. -    zmv_mlt(B,z,u);
  5423. -    if ( zv_norm2(zv_sub(u,x,u)) >= MACHEPS*zm_norm_inf(A)*zm_norm_inf(B)*5 )
  5424. -    errmesg("zmv_mlt()/zvm_mlt()");
  5425. -
  5426. -    MEMCHK();
  5427. -
  5428. -    /* get/set row/col */
  5429. -    notice("getting and setting rows and cols");
  5430. -    x = zv_resize(x,A->n);
  5431. -    y = zv_resize(y,B->m);
  5432. -    x = zget_row(A,3,x);
  5433. -    y = zget_col(B,3,y);
  5434. -    if ( zabs(zsub(_zin_prod(x,y,0,Z_NOCONJ),ONE)) >=
  5435. -    MACHEPS*zm_norm_inf(A)*zm_norm_inf(B)*5 )
  5436. -    errmesg("zget_row()/zget_col()");
  5437. -    zv_mlt(zmake(-1.0,0.0),x,x);
  5438. -    zv_mlt(zmake(-1.0,0.0),y,y);
  5439. -    zset_row(A,3,x);
  5440. -    zset_col(B,3,y);
  5441. -    zm_mlt(A,B,C);
  5442. -    for ( i = 0; i < C->m; i++ )
  5443. -    m_set_val(C,i,i,zsub(m_entry(C,i,i),ONE));
  5444. -    if ( zm_norm_inf(C) >= MACHEPS*zm_norm_inf(A)*zm_norm_inf(B)*5 )
  5445. -    errmesg("zset_row()/zset_col()");
  5446. -
  5447. -    MEMCHK();
  5448. -
  5449. -    /* matrix norms */
  5450. -    notice("matrix norms");
  5451. -    A = zm_resize(A,11,15);
  5452. -    zm_rand(A);
  5453. -    s1 = zm_norm_inf(A);
  5454. -    B = zm_adjoint(A,B);
  5455. -    s2 = zm_norm1(B);
  5456. -    if ( fabs(s1 - s2) >= MACHEPS*A->m )
  5457. -    errmesg("zm_norm1()/zm_norm_inf()");
  5458. -    C = zmam_mlt(A,A,C);
  5459. -    z1.re = z1.im = 0.0;
  5460. -    for ( i = 0; i < C->m && i < C->n; i++ )
  5461. -    z1 = zadd(z1,m_entry(C,i,i));
  5462. -    if ( fabs(sqrt(z1.re) - zm_norm_frob(A)) >= MACHEPS*A->m*A->n )
  5463. -    errmesg("zm_norm_frob");
  5464. -
  5465. -    MEMCHK();
  5466. -    
  5467. -    /* permuting rows and columns */
  5468. -    /******************************
  5469. -    notice("permuting rows & cols");
  5470. -    A = zm_resize(A,11,15);
  5471. -    B = zm_resize(B,11,15);
  5472. -    pi1 = px_resize(pi1,A->m);
  5473. -    px_rand(pi1);
  5474. -    x = zv_resize(x,A->n);
  5475. -    y = zmv_mlt(A,x,y);
  5476. -    px_rows(pi1,A,B);
  5477. -    px_zvec(pi1,y,z);
  5478. -    zmv_mlt(B,x,u);
  5479. -    if ( zv_norm2(zv_sub(z,u,u)) >= MACHEPS*A->m )
  5480. -    errmesg("px_rows()");
  5481. -    pi1 = px_resize(pi1,A->n);
  5482. -    px_rand(pi1);
  5483. -    px_cols(pi1,A,B);
  5484. -    pxinv_zvec(pi1,x,z);
  5485. -    zmv_mlt(B,z,u);
  5486. -    if ( zv_norm2(zv_sub(y,u,u)) >= MACHEPS*A->n )
  5487. -    errmesg("px_cols()");
  5488. -    ******************************/
  5489. -
  5490. -    MEMCHK();
  5491. -
  5492. -    /* MATLAB save/load */
  5493. -    notice("MATLAB save/load");
  5494. -    A = zm_resize(A,12,11);
  5495. -    if ( (fp=fopen(SAVE_FILE,"w")) == (FILE *)NULL )
  5496. -    printf("Cannot perform MATLAB save/load test\n");
  5497. -    else
  5498. -    {
  5499. -    zm_rand(A);
  5500. -    zm_save(fp, A, name);
  5501. -    fclose(fp);
  5502. -    if ( (fp=fopen(SAVE_FILE,"r")) == (FILE *)NULL )
  5503. -        printf("Cannot open save file \"%s\"\n",SAVE_FILE);
  5504. -    else
  5505. -    {
  5506. -        ZM_FREE(B);
  5507. -        B = zm_load(fp,&cp);
  5508. -        if ( strcmp(name,cp) || zm_norm1(zm_sub(A,B,C)) >=
  5509. -         MACHEPS*A->m )
  5510. -        {
  5511. -        errmesg("zm_load()/zm_save()");
  5512. -        printf("# orig. name = %s, restored name = %s\n", name, cp);
  5513. -        printf("# orig. A =\n");    zm_output(A);
  5514. -        printf("# restored A =\n");    zm_output(B);
  5515. -        }
  5516. -    }
  5517. -    }
  5518. -
  5519. -    MEMCHK();
  5520. -
  5521. -    /* Now, onto matrix factorisations */
  5522. -    A = zm_resize(A,10,10);
  5523. -    B = zm_resize(B,A->m,A->n);
  5524. -    zm_copy(A,B);
  5525. -    x = zv_resize(x,A->n);
  5526. -    y = zv_resize(y,A->m);
  5527. -    z = zv_resize(z,A->n);
  5528. -    u = zv_resize(u,A->m);
  5529. -    zv_rand(x);
  5530. -    zmv_mlt(B,x,y);
  5531. -    z = zv_copy(x,z);
  5532. -
  5533. -    notice("LU factor/solve");
  5534. -    pivot = px_get(A->m);
  5535. -    zLUfactor(A,pivot);
  5536. -    tracecatch(zLUsolve(A,pivot,y,x),"main");
  5537. -    tracecatch(cond_est = zLUcondest(A,pivot),"main");
  5538. -    printf("# cond(A) approx= %g\n", cond_est);
  5539. -    if ( zv_norm2(zv_sub(x,z,u)) >= MACHEPS*zv_norm2(x)*cond_est)
  5540. -    {
  5541. -    errmesg("zLUfactor()/zLUsolve()");
  5542. -    printf("# LU solution error = %g [cf MACHEPS = %g]\n",
  5543. -           zv_norm2(zv_sub(x,z,u)), MACHEPS);
  5544. -    }
  5545. -
  5546. -
  5547. -    zv_copy(y,x);
  5548. -    tracecatch(zLUsolve(A,pivot,x,x),"main");
  5549. -    tracecatch(cond_est = zLUcondest(A,pivot),"main");
  5550. -    if ( zv_norm2(zv_sub(x,z,u)) >= MACHEPS*zv_norm2(x)*cond_est)
  5551. -    {
  5552. -    errmesg("zLUfactor()/zLUsolve()");
  5553. -    printf("# LU solution error = %g [cf MACHEPS = %g]\n",
  5554. -           zv_norm2(zv_sub(x,z,u)), MACHEPS);
  5555. -    }
  5556. -
  5557. -    zvm_mlt(B,z,y);
  5558. -    zv_copy(y,x);
  5559. -    tracecatch(zLUAsolve(A,pivot,x,x),"main");
  5560. -    if ( zv_norm2(zv_sub(x,z,u)) >= MACHEPS*zv_norm2(x)*cond_est)
  5561. -    {
  5562. -    errmesg("zLUfactor()/zLUAsolve()");
  5563. -    printf("# LU solution error = %g [cf MACHEPS = %g]\n",
  5564. -           zv_norm2(zv_sub(x,z,u)), MACHEPS);
  5565. -    }
  5566. -
  5567. -    MEMCHK();
  5568. -
  5569. -    /* QR factorisation */
  5570. -    zm_copy(B,A);
  5571. -    zmv_mlt(B,z,y);
  5572. -    notice("QR factor/solve:");
  5573. -    diag = zv_get(A->m);
  5574. -    zQRfactor(A,diag);
  5575. -    zQRsolve(A,diag,y,x);
  5576. -    if ( zv_norm2(zv_sub(x,z,u)) >= MACHEPS*zv_norm2(x)*cond_est )
  5577. -    {
  5578. -    errmesg("zQRfactor()/zQRsolve()");
  5579. -    printf("# QR solution error = %g [cf MACHEPS = %g]\n",
  5580. -           zv_norm2(zv_sub(x,z,u)), MACHEPS);
  5581. -    }
  5582. -    printf("# QR cond(A) approx= %g\n", zQRcondest(A));
  5583. -    Q = zm_get(A->m,A->m);
  5584. -    zmakeQ(A,diag,Q);
  5585. -    zmakeR(A,A);
  5586. -    zm_mlt(Q,A,C);
  5587. -    zm_sub(B,C,C);
  5588. -    if ( zm_norm1(C) >= MACHEPS*zm_norm1(Q)*zm_norm1(B) )
  5589. -    {
  5590. -    errmesg("zQRfactor()/zmakeQ()/zmakeR()");
  5591. -    printf("# QR reconstruction error = %g [cf MACHEPS = %g]\n",
  5592. -           zm_norm1(C), MACHEPS);
  5593. -    }
  5594. -
  5595. -    MEMCHK();
  5596. -
  5597. -    /* now try with a non-square matrix */
  5598. -    A = zm_resize(A,15,7);
  5599. -    zm_rand(A);
  5600. -    B = zm_copy(A,B);
  5601. -    diag = zv_resize(diag,A->n);
  5602. -    x = zv_resize(x,A->n);
  5603. -    y = zv_resize(y,A->m);
  5604. -    zv_rand(y);
  5605. -    zQRfactor(A,diag);
  5606. -    x = zQRsolve(A,diag,y,x);
  5607. -    /* z is the residual vector */
  5608. -    zmv_mlt(B,x,z);    zv_sub(z,y,z);
  5609. -    /* check B*.z = 0 */
  5610. -    zvm_mlt(B,z,u);
  5611. -    if ( zv_norm2(u) >= 100*MACHEPS*zm_norm1(B)*zv_norm2(y) )
  5612. -    {
  5613. -    errmesg("zQRfactor()/zQRsolve()");
  5614. -    printf("# QR solution error = %g [cf MACHEPS = %g]\n",
  5615. -           zv_norm2(u), MACHEPS);
  5616. -    }
  5617. -    Q = zm_resize(Q,A->m,A->m);
  5618. -    zmakeQ(A,diag,Q);
  5619. -    zmakeR(A,A);
  5620. -    zm_mlt(Q,A,C);
  5621. -    zm_sub(B,C,C);
  5622. -    if ( zm_norm1(C) >= MACHEPS*zm_norm1(Q)*zm_norm1(B) )
  5623. -    {
  5624. -    errmesg("zQRfactor()/zmakeQ()/zmakeR()");
  5625. -    printf("# QR reconstruction error = %g [cf MACHEPS = %g]\n",
  5626. -           zm_norm1(C), MACHEPS);
  5627. -    }
  5628. -    D = zm_get(A->m,Q->m);
  5629. -    zmam_mlt(Q,Q,D);
  5630. -    for ( i = 0; i < D->m; i++ )
  5631. -    m_set_val(D,i,i,zsub(m_entry(D,i,i),ONE));
  5632. -    if ( zm_norm1(D) >= MACHEPS*zm_norm1(Q)*zm_norm_inf(Q) )
  5633. -    {
  5634. -    errmesg("QRfactor()/makeQ()/makeR()");
  5635. -    printf("# QR orthogonality error = %g [cf MACHEPS = %g]\n",
  5636. -           zm_norm1(D), MACHEPS);
  5637. -    }
  5638. -
  5639. -    MEMCHK();
  5640. -
  5641. -    /* QRCP factorisation */
  5642. -    zm_copy(B,A);
  5643. -    notice("QR factor/solve with column pivoting");
  5644. -    pivot = px_resize(pivot,A->n);
  5645. -    zQRCPfactor(A,diag,pivot);
  5646. -    z = zv_resize(z,A->n);
  5647. -    zQRCPsolve(A,diag,pivot,y,z);
  5648. -    /* pxinv_zvec(pivot,z,x); */
  5649. -    /* now compute residual (z) vector */
  5650. -    zmv_mlt(B,x,z);    zv_sub(z,y,z);
  5651. -    /* check B^T.z = 0 */
  5652. -    zvm_mlt(B,z,u);
  5653. -    if ( zv_norm2(u) >= MACHEPS*zm_norm1(B)*zv_norm2(y) )
  5654. -    {
  5655. -    errmesg("QRCPfactor()/QRsolve()");
  5656. -    printf("# QR solution error = %g [cf MACHEPS = %g]\n",
  5657. -           zv_norm2(u), MACHEPS);
  5658. -    }
  5659. -
  5660. -    Q = zm_resize(Q,A->m,A->m);
  5661. -    zmakeQ(A,diag,Q);
  5662. -    zmakeR(A,A);
  5663. -    zm_mlt(Q,A,C);
  5664. -    ZM_FREE(D);
  5665. -    D = zm_get(B->m,B->n);
  5666. -    /******************************
  5667. -    px_cols(pivot,C,D);
  5668. -    zm_sub(B,D,D);
  5669. -    if ( zm_norm1(D) >= MACHEPS*zm_norm1(Q)*zm_norm1(B) )
  5670. -    {
  5671. -    errmesg("QRCPfactor()/makeQ()/makeR()");
  5672. -    printf("# QR reconstruction error = %g [cf MACHEPS = %g]\n",
  5673. -           zm_norm1(D), MACHEPS);
  5674. -    }
  5675. -    ******************************/
  5676. -
  5677. -    /* Now check eigenvalue/SVD routines */
  5678. -    notice("complex Schur routines");
  5679. -    A = zm_resize(A,11,11);
  5680. -    B = zm_resize(B,A->m,A->n);
  5681. -    C = zm_resize(C,A->m,A->n);
  5682. -    D = zm_resize(D,A->m,A->n);
  5683. -    Q = zm_resize(Q,A->m,A->n);
  5684. -
  5685. -    MEMCHK();
  5686. -
  5687. -    /* now test complex Schur decomposition */
  5688. -    /* zm_copy(A,B); */
  5689. -    ZM_FREE(A);
  5690. -    A = zm_get(11,11);
  5691. -    zm_rand(A);
  5692. -    B = zm_copy(A,B);
  5693. -    MEMCHK();
  5694. -
  5695. -    B = zschur(B,Q);
  5696. -    MEMCHK();
  5697. -
  5698. -    zm_mlt(Q,B,C);
  5699. -    zmma_mlt(C,Q,D);
  5700. -    MEMCHK();
  5701. -    zm_sub(A,D,D);
  5702. -    if ( zm_norm1(D) >= MACHEPS*zm_norm1(Q)*zm_norm_inf(Q)*zm_norm1(B)*5 )
  5703. -    {
  5704. -    errmesg("zschur()");
  5705. -    printf("# Schur reconstruction error = %g [cf MACHEPS = %g]\n",
  5706. -           zm_norm1(D), MACHEPS);
  5707. -    }
  5708. -
  5709. -    /* orthogonality check */
  5710. -    zmma_mlt(Q,Q,D);
  5711. -    for ( i = 0; i < D->m; i++ )
  5712. -    m_set_val(D,i,i,zsub(m_entry(D,i,i),ONE));
  5713. -    if ( zm_norm1(D) >= MACHEPS*zm_norm1(Q)*zm_norm_inf(Q)*10 )
  5714. -    {
  5715. -    errmesg("zschur()");
  5716. -    printf("# Schur orthogonality error = %g [cf MACHEPS = %g]\n",
  5717. -           zm_norm1(D), MACHEPS);
  5718. -    }
  5719. -
  5720. -    MEMCHK();
  5721. -
  5722. -    /* now test SVD */
  5723. -    /******************************
  5724. -    A = zm_resize(A,11,7);
  5725. -    zm_rand(A);
  5726. -    U = zm_get(A->n,A->n);
  5727. -    Q = zm_resize(Q,A->m,A->m);
  5728. -    u = zv_resize(u,max(A->m,A->n));
  5729. -    svd(A,Q,U,u);
  5730. -    ******************************/
  5731. -    /* check reconstruction of A */
  5732. -    /******************************
  5733. -    D = zm_resize(D,A->m,A->n);
  5734. -    C = zm_resize(C,A->m,A->n);
  5735. -    zm_zero(D);
  5736. -    for ( i = 0; i < min(A->m,A->n); i++ )
  5737. -    zm_set_val(D,i,i,v_entry(u,i));
  5738. -    zmam_mlt(Q,D,C);
  5739. -    zm_mlt(C,U,D);
  5740. -    zm_sub(A,D,D);
  5741. -    if ( zm_norm1(D) >= MACHEPS*zm_norm1(U)*zm_norm_inf(Q)*zm_norm1(A) )
  5742. -    {
  5743. -    errmesg("svd()");
  5744. -    printf("# SVD reconstruction error = %g [cf MACHEPS = %g]\n",
  5745. -           zm_norm1(D), MACHEPS);
  5746. -    }
  5747. -    ******************************/
  5748. -    /* check orthogonality of Q and U */
  5749. -    /******************************
  5750. -    D = zm_resize(D,Q->n,Q->n);
  5751. -    zmam_mlt(Q,Q,D);
  5752. -    for ( i = 0; i < D->m; i++ )
  5753. -    m_set_val(D,i,i,m_entry(D,i,i)-1.0);
  5754. -    if ( zm_norm1(D) >= MACHEPS*zm_norm1(Q)*zm_norm_inf(Q)*5 )
  5755. -    {
  5756. -    errmesg("svd()");
  5757. -    printf("# SVD orthognality error (Q) = %g [cf MACHEPS = %g\n",
  5758. -           zm_norm1(D), MACHEPS);
  5759. -    }
  5760. -    D = zm_resize(D,U->n,U->n);
  5761. -    zmam_mlt(U,U,D);
  5762. -    for ( i = 0; i < D->m; i++ )
  5763. -    m_set_val(D,i,i,m_entry(D,i,i)-1.0);
  5764. -    if ( zm_norm1(D) >= MACHEPS*zm_norm1(U)*zm_norm_inf(U)*5 )
  5765. -    {
  5766. -    errmesg("svd()");
  5767. -    printf("# SVD orthognality error (U) = %g [cf MACHEPS = %g\n",
  5768. -           zm_norm1(D), MACHEPS);
  5769. -    }
  5770. -    for ( i = 0; i < u->dim; i++ )
  5771. -    if ( v_entry(u,i) < 0 || (i < u->dim-1 &&
  5772. -                  v_entry(u,i+1) > v_entry(u,i)) )
  5773. -        break;
  5774. -    if ( i < u->dim )
  5775. -    {
  5776. -    errmesg("svd()");
  5777. -    printf("# SVD sorting error\n");
  5778. -    }
  5779. -    ******************************/
  5780. -
  5781. -    ZV_FREE(x);    ZV_FREE(y);    ZV_FREE(z);
  5782. -    ZV_FREE(u);    ZV_FREE(diag);
  5783. -    PX_FREE(pi1);    PX_FREE(pi2);    PX_FREE(pivot);
  5784. -    ZM_FREE(A);    ZM_FREE(B);    ZM_FREE(C);
  5785. -    ZM_FREE(D);    ZM_FREE(Q);
  5786. -
  5787. -    mem_stat_free(1);
  5788. -
  5789. -    MEMCHK();
  5790. -    printf("# Finished torture test for complex numbers/vectors/matrices\n");
  5791. -    mem_info();
  5792. -}
  5793. -
  5794. //GO.SYSIN DD ztorture.c
  5795. echo memtort.c 1>&2
  5796. sed >memtort.c <<'//GO.SYSIN DD memtort.c' 's/^-//'
  5797. -
  5798. -/**************************************************************************
  5799. -**
  5800. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  5801. -**
  5802. -**                 Meschach Library
  5803. -** 
  5804. -** This Meschach Library is provided "as is" without any express 
  5805. -** or implied warranty of any kind with respect to this software. 
  5806. -** In particular the authors shall not be liable for any direct, 
  5807. -** indirect, special, incidental or consequential damages arising 
  5808. -** in any way from use of the software.
  5809. -** 
  5810. -** Everyone is granted permission to copy, modify and redistribute this
  5811. -** Meschach Library, provided:
  5812. -**  1.  All copies contain this copyright notice.
  5813. -**  2.  All modified copies shall carry a notice stating who
  5814. -**      made the last modification and the date of such modification.
  5815. -**  3.  No charge is made for this software or works derived from it.  
  5816. -**      This clause shall not be construed as constraining other software
  5817. -**      distributed on the same medium as this software, nor is a
  5818. -**      distribution fee considered a charge.
  5819. -**
  5820. -***************************************************************************/
  5821. -
  5822. -
  5823. -/* 
  5824. -  Tests for mem_info.c functions
  5825. -  */
  5826. -
  5827. -static char rcsid[] = "$Id: $";
  5828. -
  5829. -#include        <stdio.h>
  5830. -#include        <math.h>
  5831. -#include        "matrix2.h"
  5832. -#include     "sparse2.h"
  5833. -#include      "zmatrix2.h"
  5834. -
  5835. -
  5836. -#define errmesg(mesg)   printf("Error: %s error: line %d\n",mesg,__LINE__)
  5837. -#define notice(mesg)    printf("# Testing %s...\n",mesg)
  5838. -
  5839. -
  5840. -/*  new types list */
  5841. -
  5842. -extern MEM_CONNECT mem_connect[MEM_CONNECT_MAX_LISTS];
  5843. -
  5844. -/* the number of a new list */
  5845. -#define FOO_LIST 1
  5846. -
  5847. -/* numbers of types */
  5848. -#define TYPE_FOO_1    1
  5849. -#define TYPE_FOO_2    2
  5850. -
  5851. -typedef struct {
  5852. -   int dim;
  5853. -   int fix_dim;
  5854. -   Real (*a)[10];
  5855. -} FOO_1;
  5856. -
  5857. -typedef struct {
  5858. -  int dim;
  5859. -  int fix_dim;
  5860. -  Real (*a)[2];
  5861. -} FOO_2;
  5862. -
  5863. -
  5864. -
  5865. -FOO_1 *foo_1_get(dim)
  5866. -int dim;
  5867. -{
  5868. -   FOO_1 *f;
  5869. -   
  5870. -   if ((f = (FOO_1 *)malloc(sizeof(FOO_1))) == NULL)
  5871. -     error(E_MEM,"foo_1_get");
  5872. -   else if (mem_info_is_on()) {
  5873. -      mem_bytes_list(TYPE_FOO_1,0,sizeof(FOO_1),FOO_LIST);
  5874. -      mem_numvar_list(TYPE_FOO_1,1,FOO_LIST);
  5875. -   }
  5876. -   
  5877. -   f->dim = dim;
  5878. -   f->fix_dim = 10;
  5879. -   if ((f->a = (Real (*)[10])malloc(dim*sizeof(Real [10]))) == NULL)
  5880. -      error(E_MEM,"foo_1_get");
  5881. -   else if (mem_info_is_on())
  5882. -     mem_bytes_list(TYPE_FOO_1,0,dim*sizeof(Real [10]),FOO_LIST); 
  5883. -
  5884. -   return f;
  5885. -}
  5886. -
  5887. -
  5888. -FOO_2 *foo_2_get(dim)
  5889. -int dim;
  5890. -{
  5891. -   FOO_2 *f;
  5892. -   
  5893. -   if ((f = (FOO_2 *)malloc(sizeof(FOO_2))) == NULL)
  5894. -     error(E_MEM,"foo_2_get");
  5895. -   else if (mem_info_is_on()) {
  5896. -      mem_bytes_list(TYPE_FOO_2,0,sizeof(FOO_2),FOO_LIST);
  5897. -      mem_numvar_list(TYPE_FOO_2,1,FOO_LIST);
  5898. -   }
  5899. -
  5900. -   f->dim = dim;
  5901. -   f->fix_dim = 2;
  5902. -   if ((f->a = (Real (*)[2])malloc(dim*sizeof(Real [2]))) == NULL)
  5903. -      error(E_MEM,"foo_2_get");
  5904. -   else if (mem_info_is_on())
  5905. -     mem_bytes_list(TYPE_FOO_2,0,dim*sizeof(Real [2]),FOO_LIST); 
  5906. -
  5907. -   return f;
  5908. -}
  5909. -
  5910. -
  5911. -
  5912. -int foo_1_free(f)
  5913. -FOO_1 *f;
  5914. -{
  5915. -   if ( f != NULL) {
  5916. -      if (mem_info_is_on()) {
  5917. -     mem_bytes_list(TYPE_FOO_1,sizeof(FOO_1)+
  5918. -            f->dim*sizeof(Real [10]),0,FOO_LIST);
  5919. -     mem_numvar_list(TYPE_FOO_1,-1,FOO_LIST);
  5920. -      }
  5921. -
  5922. -      free(f->a);
  5923. -      free(f);
  5924. -   }
  5925. -   return 0;
  5926. -}
  5927. -
  5928. -int foo_2_free(f)
  5929. -FOO_2 *f;
  5930. -{
  5931. -   if ( f != NULL) {
  5932. -      if (mem_info_is_on()) {
  5933. -     mem_bytes_list(TYPE_FOO_2,sizeof(FOO_2)+
  5934. -            f->dim*sizeof(Real [2]),0,FOO_LIST);
  5935. -     mem_numvar_list(TYPE_FOO_2,-1,FOO_LIST);
  5936. -      }
  5937. -
  5938. -      free(f->a);
  5939. -      free(f);
  5940. -   }
  5941. -   return 0;
  5942. -}
  5943. -
  5944. -
  5945. -
  5946. -
  5947. -char *foo_type_name[] = {
  5948. -   "nothing",
  5949. -   "FOO_1",
  5950. -   "FOO_2"
  5951. -};
  5952. -
  5953. -
  5954. -#define FOO_NUM_TYPES  (sizeof(foo_type_name)/sizeof(*foo_type_name))
  5955. -
  5956. -
  5957. -int (*foo_free_func[FOO_NUM_TYPES])() = {
  5958. -   NULL, 
  5959. -   foo_1_free, 
  5960. -   foo_2_free
  5961. -  };
  5962. -
  5963. -
  5964. -
  5965. -static MEM_ARRAY foo_info_sum[FOO_NUM_TYPES];
  5966. -
  5967. -
  5968. -
  5969. -  /* px_rand -- generates sort-of random permutation */
  5970. -PERM    *px_rand(pi)
  5971. -PERM    *pi;
  5972. -{
  5973. -   int         i, j, k;
  5974. -   
  5975. -   if ( ! pi )
  5976. -     error(E_NULL,"px_rand");
  5977. -   
  5978. -   for ( i = 0; i < 3*pi->size; i++ )
  5979. -   {
  5980. -      j = (rand() >> 8) % pi->size;
  5981. -      k = (rand() >> 8) % pi->size;
  5982. -      px_transp(pi,j,k);
  5983. -   }
  5984. -   
  5985. -   return pi;
  5986. -}
  5987. -
  5988. -#ifdef SPARSE
  5989. -SPMAT  *gen_non_symm(m,n)
  5990. -int     m, n;
  5991. -{
  5992. -    SPMAT      *A;
  5993. -    static      PERM    *px = PNULL;
  5994. -    int         i, j, k, k_max;
  5995. -    Real        s1;
  5996. -
  5997. -    A = sp_get(m,n,8);
  5998. -    px = px_resize(px,n);
  5999. -    MEM_STAT_REG(px,TYPE_PERM);
  6000. -    for ( i = 0; i < A->m; i++ )
  6001. -    {
  6002. -        k_max = 1 + ((rand() >> 8) % 10);
  6003. -        for ( k = 0; k < k_max; k++ )
  6004. -        {
  6005. -            j = (rand() >> 8) % A->n;
  6006. -            s1 = rand()/((double)MAX_RAND);
  6007. -            sp_set_val(A,i,j,s1);
  6008. -        }
  6009. -    }
  6010. -    /* to make it likely that A is nonsingular, use pivot... */
  6011. -    for ( i = 0; i < 2*A->n; i++ )
  6012. -    {
  6013. -        j = (rand() >> 8) % A->n;
  6014. -        k = (rand() >> 8) % A->n;
  6015. -        px_transp(px,j,k);
  6016. -    }
  6017. -    for ( i = 0; i < A->n; i++ )
  6018. -        sp_set_val(A,i,px->pe[i],1.0);
  6019. -
  6020. -    
  6021. -    return A;
  6022. -}
  6023. -#endif
  6024. -
  6025. -void stat_test1(par)
  6026. -int par;
  6027. -{
  6028. -   static MAT *AT = MNULL;
  6029. -   static VEC *xt1 = VNULL, *yt1 = VNULL;
  6030. -   static VEC *xt2 = VNULL, *yt2 = VNULL;
  6031. -   static VEC *xt3 = VNULL, *yt3 = VNULL;
  6032. -   static VEC *xt4 = VNULL, *yt4 = VNULL;
  6033. -
  6034. -   AT = m_resize(AT,10,10);
  6035. -   xt1 = v_resize(xt1,10);
  6036. -   yt1 = v_resize(yt1,10);
  6037. -   xt2 = v_resize(xt2,10);
  6038. -   yt2 = v_resize(yt2,10);
  6039. -   xt3 = v_resize(xt3,10);
  6040. -   yt3 = v_resize(yt3,10);
  6041. -   xt4 = v_resize(xt4,10);
  6042. -   yt4 = v_resize(yt4,10);
  6043. -
  6044. -   MEM_STAT_REG(AT,TYPE_MAT);
  6045. -
  6046. -#ifdef ANSI_C
  6047. -   mem_stat_reg_vars(0,TYPE_VEC,&xt1,&xt2,&xt3,&xt4,&yt1,
  6048. -             &yt2,&yt3,&yt4,NULL);
  6049. -#else
  6050. -#ifdef VARARGS
  6051. -   mem_stat_reg_vars(0,TYPE_VEC,&xt1,&xt2,&xt3,&xt4,&yt1,
  6052. -             &yt2,&yt3,&yt4,NULL);
  6053. -#else
  6054. -   MEM_STAT_REG(xt1,TYPE_VEC);
  6055. -   MEM_STAT_REG(yt1,TYPE_VEC);
  6056. -   MEM_STAT_REG(xt2,TYPE_VEC);
  6057. -   MEM_STAT_REG(yt2,TYPE_VEC);
  6058. -   MEM_STAT_REG(xt3,TYPE_VEC);
  6059. -   MEM_STAT_REG(yt3,TYPE_VEC);
  6060. -   MEM_STAT_REG(xt4,TYPE_VEC);
  6061. -   MEM_STAT_REG(yt4,TYPE_VEC);
  6062. -#endif
  6063. -#endif
  6064. -
  6065. -   v_rand(xt1);
  6066. -   m_rand(AT);
  6067. -   mv_mlt(AT,xt1,yt1);
  6068. -   
  6069. -}
  6070. -
  6071. -
  6072. -void stat_test2(par)
  6073. -int par;
  6074. -{
  6075. -   static PERM *px = PNULL;
  6076. -   static IVEC *ixt = IVNULL, *iyt = IVNULL;
  6077. -   
  6078. -   px = px_resize(px,10);
  6079. -   ixt = iv_resize(ixt,10);
  6080. -   iyt = iv_resize(iyt,10);
  6081. -
  6082. -   MEM_STAT_REG(px,TYPE_PERM);
  6083. -   MEM_STAT_REG(ixt,TYPE_IVEC);
  6084. -   MEM_STAT_REG(iyt,TYPE_IVEC);
  6085. -
  6086. -   px_rand(px);
  6087. -   px_inv(px,px);
  6088. -}
  6089. -
  6090. -#ifdef SPARSE
  6091. -void stat_test3(par)
  6092. -int par;
  6093. -{
  6094. -   static SPMAT *AT = (SPMAT *)NULL;
  6095. -   static VEC *xt = VNULL, *yt = VNULL;
  6096. -   static SPROW *r = (SPROW *) NULL;
  6097. -   
  6098. -   if (AT == (SPMAT *)NULL)
  6099. -     AT = gen_non_symm(100,100);
  6100. -   else
  6101. -     AT = sp_resize(AT,100,100);
  6102. -   xt = v_resize(xt,100);
  6103. -   yt = v_resize(yt,100);
  6104. -   if (r == NULL) r = sprow_get(100);
  6105. -
  6106. -   MEM_STAT_REG(AT,TYPE_SPMAT);
  6107. -   MEM_STAT_REG(xt,TYPE_VEC);
  6108. -   MEM_STAT_REG(yt,TYPE_VEC);
  6109. -   MEM_STAT_REG(r,TYPE_SPROW);
  6110. -
  6111. -   v_rand(xt);
  6112. -   sp_mv_mlt(AT,xt,yt);
  6113. -   
  6114. -}
  6115. -#endif
  6116. -
  6117. -#ifdef COMPLEX
  6118. -void stat_test4(par)
  6119. -int par;
  6120. -{
  6121. -   static ZMAT *AT = ZMNULL;
  6122. -   static ZVEC *xt = ZVNULL, *yt = ZVNULL;
  6123. -   
  6124. -   AT = zm_resize(AT,10,10);
  6125. -   xt = zv_resize(xt,10);
  6126. -   yt = zv_resize(yt,10);
  6127. -
  6128. -   MEM_STAT_REG(AT,TYPE_ZMAT);
  6129. -   MEM_STAT_REG(xt,TYPE_ZVEC);
  6130. -   MEM_STAT_REG(yt,TYPE_ZVEC);
  6131. -
  6132. -   zv_rand(xt);
  6133. -   zm_rand(AT);
  6134. -   zmv_mlt(AT,xt,yt);
  6135. -   
  6136. -}
  6137. -#endif
  6138. -
  6139. -
  6140. -void main(argc, argv)
  6141. -int     argc;
  6142. -char    *argv[];
  6143. -{
  6144. -   VEC  *x = VNULL, *y = VNULL, *z = VNULL;
  6145. -   PERM  *pi1 = PNULL, *pi2 = PNULL, *pi3 = PNULL;
  6146. -   MAT   *A = MNULL, *B = MNULL, *C = MNULL;
  6147. -#ifdef SPARSE
  6148. -   SPMAT *sA, *sB;
  6149. -   SPROW *r;
  6150. -#endif
  6151. -   IVEC *ix = IVNULL, *iy = IVNULL, *iz = IVNULL;
  6152. -   int m,n,i,j,deg,k;
  6153. -   Real s1,s2;
  6154. -#ifdef COMPLEX
  6155. -   ZVEC        *zx = ZVNULL, *zy = ZVNULL, *zz = ZVNULL;
  6156. -   ZMAT        *zA = ZMNULL, *zB = ZMNULL, *zC = ZMNULL;
  6157. -   complex     ONE;
  6158. -#endif
  6159. -   /* variables for testing attaching new lists of types  */
  6160. -   FOO_1 *foo_1;
  6161. -   FOO_2 *foo_2;
  6162. -
  6163. -
  6164. -   mem_info_on(TRUE);
  6165. -
  6166. -#if defined(ANSI_C) || defined(VARARGS)
  6167. -
  6168. -   notice("vector initialize, copy & resize");
  6169. -   
  6170. -   n = v_get_vars(15,&x,&y,&z,(VEC **)NULL);
  6171. -   if (n != 3) {
  6172. -      errmesg("v_get_vars");
  6173. -      printf(" n = %d (should be 3)\n",n);
  6174. -   }
  6175. -
  6176. -   v_rand(x);
  6177. -   v_rand(y);
  6178. -   z = v_copy(x,z);
  6179. -   if ( v_norm2(v_sub(x,z,z)) >= MACHEPS )
  6180. -     errmesg("v_get_vars");
  6181. -   v_copy(x,y);
  6182. -   n = v_resize_vars(10,&x,&y,&z,NULL);
  6183. -   if ( n != 3 || v_norm2(v_sub(x,y,z)) >= MACHEPS )
  6184. -     errmesg("VEC copy/resize");
  6185. -
  6186. -   n = v_resize_vars(20,&x,&y,&z,NULL);
  6187. -   if ( n != 3 || v_norm2(v_sub(x,y,z)) >= MACHEPS )
  6188. -     errmesg("VEC resize"); 
  6189. -
  6190. -   n = v_free_vars(&x,&y,&z,NULL);
  6191. -   if (n != 3)
  6192. -     errmesg("v_free_vars");
  6193. -   
  6194. -   /* IVEC */
  6195. -   notice("int vector initialise, copy & resize");
  6196. -   n = iv_get_vars(15,&ix,&iy,&iz,NULL);
  6197. -
  6198. -   if (n != 3) {
  6199. -      errmesg("iv_get_vars");
  6200. -      printf(" n = %d (should be 3)\n",n);
  6201. -   }
  6202. -   for (i=0; i < ix->dim; i++) {
  6203. -      ix->ive[i] = 2*i-1;
  6204. -      iy->ive[i] = 3*i+2;
  6205. -   }
  6206. -   iz = iv_add(ix,iy,iz);
  6207. -   for (i=0; i < ix->dim; i++) 
  6208. -     if ( iz->ive[i] != 5*i+1)
  6209. -       errmesg("iv_get_vars");
  6210. -   
  6211. -   n = iv_resize_vars(10,&ix,&iy,&iz,NULL);
  6212. -   if ( n != 3) errmesg("IVEC copy/resize");
  6213. -   
  6214. -   iv_add(ix,iy,iz);
  6215. -   for (i=0; i < ix->dim; i++)
  6216. -     if (iz->ive[i] != 5*i+1)
  6217. -       errmesg("IVEC copy/resize");
  6218. -   
  6219. -   n = iv_resize_vars(20,&ix,&iy,&iz,NULL);
  6220. -   if ( n != 3 ) errmesg("IVEC resize");
  6221. -   
  6222. -   iv_add(ix,iy,iz);
  6223. -   for (i=0; i < 10; i++)
  6224. -     if (iz->ive[i] != 5*i+1)
  6225. -       errmesg("IVEC copy/resize");
  6226. -   
  6227. -   n = iv_free_vars(&ix,&iy,&iz,NULL);
  6228. -   if (n != 3) 
  6229. -     errmesg("iv_free_vars");
  6230. -   
  6231. -   /* MAT */
  6232. -   notice("matrix initialise, copy & resize");
  6233. -   n = m_get_vars(10,10,&A,&B,&C,NULL);
  6234. -   if (n != 3) {
  6235. -      errmesg("m_get_vars");
  6236. -      printf(" n = %d (should be 3)\n",n);
  6237. -   }
  6238. -   
  6239. -   m_rand(A);
  6240. -   m_rand(B);
  6241. -   C = m_copy(A,C);
  6242. -   if ( m_norm_inf(m_sub(A,C,C)) >= MACHEPS )
  6243. -     errmesg("MAT copy");
  6244. -   m_copy(A,B);
  6245. -   n = m_resize_vars(5,5,&A,&B,&C,NULL);
  6246. -   if ( n != 3 || m_norm_inf(m_sub(A,B,C)) >= MACHEPS )
  6247. -     errmesg("MAT copy/resize");
  6248. -   
  6249. -   n = m_resize_vars(20,20,&A,&B,NULL);
  6250. -   if ( m_norm_inf(m_sub(A,B,C)) >= MACHEPS )
  6251. -     errmesg("MAT resize"); 
  6252. -   
  6253. -   k = m_free_vars(&A,&B,&C,NULL);
  6254. -   if ( k != 3 )
  6255. -     errmesg("MAT free");
  6256. -   
  6257. -   /* PERM */
  6258. -   notice("permutation initialise, inverting & permuting vectors");
  6259. -   n = px_get_vars(15,&pi1,&pi2,&pi3,NULL);
  6260. -   if (n != 3) {
  6261. -      errmesg("px_get_vars");
  6262. -      printf(" n = %d (should be 3)\n",n);
  6263. -   }
  6264. -
  6265. -   v_get_vars(15,&x,&y,&z,NULL);
  6266. -   
  6267. -   px_rand(pi1);
  6268. -   v_rand(x);
  6269. -   px_vec(pi1,x,z);
  6270. -   y = v_resize(y,x->dim);
  6271. -   pxinv_vec(pi1,z,y);
  6272. -   if ( v_norm2(v_sub(x,y,z)) >= MACHEPS )
  6273. -     errmesg("PERMute vector");
  6274. -   pi2 = px_inv(pi1,pi2);
  6275. -   pi3 = px_mlt(pi1,pi2,pi3);
  6276. -   for ( i = 0; i < pi3->size; i++ )
  6277. -     if ( pi3->pe[i] != i )
  6278. -       errmesg("PERM inverse/multiply");
  6279. -   
  6280. -   px_resize_vars(20,&pi1,&pi2,&pi3,NULL);
  6281. -   v_resize_vars(20,&x,&y,&z,NULL);
  6282. -   
  6283. -   px_rand(pi1);
  6284. -   v_rand(x);
  6285. -   px_vec(pi1,x,z);
  6286. -   pxinv_vec(pi1,z,y);
  6287. -   if ( v_norm2(v_sub(x,y,z)) >= MACHEPS )
  6288. -     errmesg("PERMute vector");
  6289. -   pi2 = px_inv(pi1,pi2);
  6290. -   pi3 = px_mlt(pi1,pi2,pi3);
  6291. -   for ( i = 0; i < pi3->size; i++ )
  6292. -     if ( pi3->pe[i] != i )
  6293. -       errmesg("PERM inverse/multiply");
  6294. -   
  6295. -   n = px_free_vars(&pi1,&pi2,&pi3,NULL);
  6296. -   if ( n != 3 )
  6297. -     errmesg("PERM px_free_vars"); 
  6298. -
  6299. -#ifdef SPARSE   
  6300. -   /* set up two random sparse matrices */
  6301. -   m = 120;
  6302. -   n = 100;
  6303. -   deg = 5;
  6304. -   notice("allocating sparse matrices");
  6305. -   k = sp_get_vars(m,n,deg,&sA,&sB,NULL);
  6306. -   if (k != 2) {
  6307. -      errmesg("sp_get_vars");
  6308. -      printf(" n = %d (should be 2)\n",k);
  6309. -   }
  6310. -   
  6311. -   notice("setting and getting matrix entries");
  6312. -   for ( k = 0; k < m*deg; k++ )
  6313. -   {
  6314. -      i = (rand() >> 8) % m;
  6315. -      j = (rand() >> 8) % n;
  6316. -      sp_set_val(sA,i,j,rand()/((Real)MAX_RAND));
  6317. -      i = (rand() >> 8) % m;
  6318. -      j = (rand() >> 8) % n;
  6319. -      sp_set_val(sB,i,j,rand()/((Real)MAX_RAND));
  6320. -   }
  6321. -   for ( k = 0; k < 10; k++ )
  6322. -   {
  6323. -      s1 = rand()/((Real)MAX_RAND);
  6324. -      i = (rand() >> 8) % m;
  6325. -      j = (rand() >> 8) % n;
  6326. -      sp_set_val(sA,i,j,s1);
  6327. -      s2 = sp_get_val(sA,i,j);
  6328. -      if ( fabs(s1 - s2) >= MACHEPS ) {
  6329. -     printf(" s1 = %g, s2 = %g, |s1 - s2| = %g\n", 
  6330. -        s1,s2,fabs(s1-s2));
  6331. -     break;
  6332. -      }
  6333. -   }
  6334. -   if ( k < 10 )
  6335. -     errmesg("sp_set_val()/sp_get_val()");
  6336. -   
  6337. -   /* check column access paths */
  6338. -   notice("resizing and access paths");
  6339. -   k = sp_resize_vars(sA->m+10,sA->n+10,&sA,&sB,NULL);
  6340. -   if (k != 2) {
  6341. -      errmesg("sp_get_vars");
  6342. -      printf(" n = %d (should be 2)\n",k);
  6343. -   }
  6344. -   
  6345. -   for ( k = 0 ; k < 20; k++ )
  6346. -   {
  6347. -      i = sA->m - 1 - ((rand() >> 8) % 10);
  6348. -      j = sA->n - 1 - ((rand() >> 8) % 10);
  6349. -      s1 = rand()/((Real)MAX_RAND);
  6350. -      sp_set_val(sA,i,j,s1);
  6351. -      if ( fabs(s1 - sp_get_val(sA,i,j)) >= MACHEPS )
  6352. -    break;
  6353. -   }
  6354. -   if ( k < 20 )
  6355. -     errmesg("sp_resize()");
  6356. -   sp_col_access(sA);
  6357. -   if ( ! chk_col_access(sA) )
  6358. -   {
  6359. -      errmesg("sp_col_access()");
  6360. -   }
  6361. -   sp_diag_access(sA);
  6362. -   for ( i = 0; i < sA->m; i++ )
  6363. -   {
  6364. -      r = &(sA->row[i]);
  6365. -      if ( r->diag != sprow_idx(r,i) )
  6366. -    break;
  6367. -   }
  6368. -   if ( i < sA->m )
  6369. -   {
  6370. -      errmesg("sp_diag_access()");
  6371. -   }
  6372. -   
  6373. -   k = sp_free_vars(&sA,&sB,NULL);
  6374. -   if (k != 2)
  6375. -     errmesg("sp_free_vars");
  6376. -#endif  /* SPARSE */   
  6377. -
  6378. -
  6379. -#ifdef COMPLEX
  6380. -   /* complex stuff */
  6381. -   
  6382. -   ONE = zmake(1.0,0.0);
  6383. -   printf("# ONE = "); z_output(ONE);
  6384. -   printf("# Check: MACHEPS = %g\n",MACHEPS);
  6385. -   /* allocate, initialise, copy and resize operations */
  6386. -   /* ZVEC */
  6387. -   notice("vector initialise, copy & resize");
  6388. -   zv_get_vars(12,&zx,&zy,&zz,NULL);
  6389. -   
  6390. -   zv_rand(zx);
  6391. -   zv_rand(zy);
  6392. -   zz = zv_copy(zx,zz);
  6393. -   if ( zv_norm2(zv_sub(zx,zz,zz)) >= MACHEPS )
  6394. -     errmesg("ZVEC copy");
  6395. -   zv_copy(zx,zy);
  6396. -   
  6397. -   zv_resize_vars(10,&zx,&zy,NULL);
  6398. -   if ( zv_norm2(zv_sub(zx,zy,zz)) >= MACHEPS )
  6399. -     errmesg("ZVEC copy/resize");
  6400. -   
  6401. -   zv_resize_vars(20,&zx,&zy,NULL);
  6402. -   if ( zv_norm2(zv_sub(zx,zy,zz)) >= MACHEPS )
  6403. -     errmesg("VZEC resize");
  6404. -   zv_free_vars(&zx,&zy,&zz,NULL);
  6405. -
  6406. -   
  6407. -   /* ZMAT */
  6408. -   notice("matrix initialise, copy & resize");
  6409. -   zm_get_vars(8,5,&zA,&zB,&zC,NULL);
  6410. -   
  6411. -   zm_rand(zA);
  6412. -   zm_rand(zB);
  6413. -   zC = zm_copy(zA,zC);
  6414. -   if ( zm_norm_inf(zm_sub(zA,zC,zC)) >= MACHEPS )
  6415. -     errmesg("ZMAT copy");
  6416. -   
  6417. -   zm_copy(zA,zB);
  6418. -   zm_resize_vars(3,5,&zA,&zB,&zC,NULL);
  6419. -   
  6420. -   if ( zm_norm_inf(zm_sub(zA,zB,zC)) >= MACHEPS )
  6421. -     errmesg("ZMAT copy/resize");
  6422. -   zm_resize_vars(20,20,&zA,&zB,&zC,NULL);
  6423. -   
  6424. -   if ( zm_norm_inf(zm_sub(zA,zB,zC)) >= MACHEPS )
  6425. -     errmesg("ZMAT resize");
  6426. -   
  6427. -   zm_free_vars(&zA,&zB,&zC,NULL);
  6428. -#endif /* COMPLEX */
  6429. -
  6430. -#endif  /* if defined(ANSI_C) || defined(VARARGS) */
  6431. -
  6432. -   printf("# test of mem_info_bytes and mem_info_numvar\n");
  6433. -   printf("  TYPE VEC: %ld bytes allocated, %d variables allocated\n",
  6434. -      mem_info_bytes(TYPE_VEC,0),mem_info_numvar(TYPE_VEC,0));
  6435. -
  6436. -   notice("static memory test");
  6437. -   mem_info_on(TRUE);
  6438. -   mem_stat_mark(1);
  6439. -   for (i=0; i < 100; i++)
  6440. -     stat_test1(i);
  6441. -   mem_stat_free(1);
  6442. -
  6443. -   mem_stat_mark(1);
  6444. -   for (i=0; i < 100; i++) {
  6445. -     stat_test1(i);
  6446. -#ifdef COMPLEX
  6447. -     stat_test4(i);
  6448. -#endif
  6449. -  }
  6450. -
  6451. -   mem_stat_mark(2);
  6452. -   for (i=0; i < 100; i++)
  6453. -     stat_test2(i);
  6454. -
  6455. -   mem_stat_mark(3);
  6456. -#ifdef SPARSE
  6457. -   for (i=0; i < 100; i++)
  6458. -     stat_test3(i);
  6459. -#endif
  6460. -
  6461. -   mem_info();
  6462. -   mem_dump_list(stdout,0);
  6463. -
  6464. -   mem_stat_free(1);
  6465. -   mem_stat_free(3);
  6466. -   mem_stat_mark(4);
  6467. -
  6468. -   for (i=0; i < 100; i++) {
  6469. -      stat_test1(i);
  6470. -#ifdef COMPLEX
  6471. -      stat_test4(i);
  6472. -#endif
  6473. -   } 
  6474. -
  6475. -   mem_stat_dump(stdout,0);
  6476. -   if (mem_stat_show_mark() != 4) {
  6477. -      errmesg("not 4 in mem_stat_show_mark()");
  6478. -   }
  6479. -   
  6480. -   mem_stat_free(2);
  6481. -   mem_stat_free(4);
  6482. -
  6483. -   if (mem_stat_show_mark() != 0) {
  6484. -      errmesg("not 0 in mem_stat_show_mark()");
  6485. -   }
  6486. -
  6487. -   /* add new list of types */
  6488. -
  6489. -   mem_attach_list(FOO_LIST,FOO_NUM_TYPES,foo_type_name,
  6490. -           foo_free_func,foo_info_sum);
  6491. -   if (!mem_is_list_attached(FOO_LIST))
  6492. -     errmesg("list FOO_LIST is not attached");
  6493. -
  6494. -   mem_dump_list(stdout,FOO_LIST);
  6495. -   foo_1 = foo_1_get(6);
  6496. -   foo_2 = foo_2_get(3);
  6497. -   for (i=0; i < foo_1->dim; i++)
  6498. -     for (j=0; j < foo_1->fix_dim; j++)
  6499. -       foo_1->a[i][j] = i+j;
  6500. -   for (i=0; i < foo_2->dim; i++)
  6501. -     for (j=0; j < foo_2->fix_dim; j++)
  6502. -       foo_2->a[i][j] = i+j;
  6503. -   printf(" foo_1->a[%d][%d] = %g\n",5,9,foo_1->a[5][9]);
  6504. -   printf(" foo_2->a[%d][%d] = %g\n",2,1,foo_2->a[2][1]);
  6505. -   
  6506. -   mem_stat_mark(5);
  6507. -   mem_stat_reg_list((void **)&foo_1,TYPE_FOO_1,FOO_LIST);
  6508. -   mem_stat_reg_list((void **)&foo_2,TYPE_FOO_2,FOO_LIST);
  6509. -   mem_stat_dump(stdout,FOO_LIST);
  6510. -   mem_info_file(stdout,FOO_LIST);
  6511. -   mem_stat_free_list(5,FOO_LIST);
  6512. -   mem_stat_dump(stdout,FOO_LIST);
  6513. -   if ( foo_1 != NULL )
  6514. -     errmesg(" foo_1 is not released");
  6515. -   if ( foo_2 != NULL )
  6516. -     errmesg(" foo_2 is not released");
  6517. -   mem_dump_list(stdout,FOO_LIST);
  6518. -   mem_info_file(stdout,FOO_LIST);
  6519. -
  6520. -   mem_free_vars(FOO_LIST);
  6521. -   if ( mem_is_list_attached(FOO_LIST) )
  6522. -     errmesg("list FOO_LIST is not detached");
  6523. -
  6524. -   mem_info();
  6525. -   
  6526. -#if REAL == FLOAT
  6527. -   printf("# SINGLE PRECISION was used\n");
  6528. -#elif REAL == DOUBLE
  6529. -   printf("# DOUBLE PRECISION was used\n");
  6530. -#endif
  6531. -
  6532. -#define ANSI_OR_VAR
  6533. -
  6534. -#ifndef ANSI_C
  6535. -#ifndef VARARGS
  6536. -#undef ANSI_OR_VAR
  6537. -#endif
  6538. -#endif
  6539. -
  6540. -#ifdef ANSI_OR_VAR
  6541. -
  6542. -   printf("# you should get: \n");
  6543. -#if (REAL == FLOAT)
  6544. -     printf("#   type VEC: 276 bytes allocated, 3 variables allocated\n");
  6545. -#elif (REAL == DOUBLE)
  6546. -     printf("#   type VEC: 516 bytes allocated, 3 variables allocated\n");
  6547. -#endif
  6548. -   printf("#   and other types are zeros\n");
  6549. -
  6550. -#endif /*#if defined(ANSI_C) || defined(VARAGS) */
  6551. -
  6552. -   printf("# Finished memory torture test\n");
  6553. -   return;
  6554. -}
  6555. //GO.SYSIN DD memtort.c
  6556. echo itertort.c 1>&2
  6557. sed >itertort.c <<'//GO.SYSIN DD itertort.c' 's/^-//'
  6558. -
  6559. -/**************************************************************************
  6560. -**
  6561. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  6562. -**
  6563. -**                 Meschach Library
  6564. -** 
  6565. -** This Meschach Library is provided "as is" without any express 
  6566. -** or implied warranty of any kind with respect to this software. 
  6567. -** In particular the authors shall not be liable for any direct, 
  6568. -** indirect, special, incidental or consequential damages arising 
  6569. -** in any way from use of the software.
  6570. -** 
  6571. -** Everyone is granted permission to copy, modify and redistribute this
  6572. -** Meschach Library, provided:
  6573. -**  1.  All copies contain this copyright notice.
  6574. -**  2.  All modified copies shall carry a notice stating who
  6575. -**      made the last modification and the date of such modification.
  6576. -**  3.  No charge is made for this software or works derived from it.  
  6577. -**      This clause shall not be construed as constraining other software
  6578. -**      distributed on the same medium as this software, nor is a
  6579. -**      distribution fee considered a charge.
  6580. -**
  6581. -***************************************************************************/
  6582. -
  6583. -
  6584. -/*  iter_tort.c  16/09/93 */
  6585. -
  6586. -/*
  6587. -  This file contains tests for the iterative part of Meschach
  6588. -*/
  6589. -
  6590. -#include    <stdio.h>
  6591. -#include    <math.h>
  6592. -#include    "matrix2.h"
  6593. -#include    "sparse2.h"
  6594. -#include    "iter.h"
  6595. -
  6596. -#define    errmesg(mesg)    printf("Error: %s error: line %d\n",mesg,__LINE__)
  6597. -#define notice(mesg)    printf("# Testing %s...\n",mesg);
  6598. -  
  6599. -  /* for iterative methods */
  6600. -  
  6601. -#if REAL == DOUBLE
  6602. -#define    EPS    1e-7
  6603. -#define KK    20
  6604. -#elif REAL == FLOAT
  6605. -#define EPS   1e-5
  6606. -#define KK    8
  6607. -#endif
  6608. -
  6609. -#define ANON  513
  6610. -#define ASYM  ANON   
  6611. -
  6612. -  
  6613. -static VEC *ex_sol = VNULL;
  6614. -
  6615. -/* new iter information */
  6616. -void iter_mod_info(ip,nres,res,Bres)
  6617. -ITER *ip;
  6618. -double nres;
  6619. -VEC *res, *Bres;
  6620. -{
  6621. -   static VEC *tmp;
  6622. -
  6623. -   if (ip->b == VNULL) return;
  6624. -   tmp = v_resize(tmp,ip->b->dim);
  6625. -   MEM_STAT_REG(tmp,TYPE_VEC);
  6626. -
  6627. -   if (nres >= 0.0) {
  6628. -      printf(" %d. residual = %g\n",ip->steps,nres);
  6629. -   }
  6630. -   else 
  6631. -     printf(" %d. residual = %g (WARNING !!! should be >= 0) \n",
  6632. -        ip->steps,nres);
  6633. -   if (ex_sol != VNULL)
  6634. -     printf("    ||u_ex - u_approx||_2 = %g\n",
  6635. -        v_norm2(v_sub(ip->x,ex_sol,tmp)));
  6636. -}
  6637. -
  6638. -
  6639. -/* out = A^T*A*x */
  6640. -VEC *norm_equ(A,x,out)
  6641. -SPMAT *A;
  6642. -VEC *x, *out;
  6643. -{
  6644. -   static VEC * tmp;
  6645. -
  6646. -   tmp = v_resize(tmp,x->dim);
  6647. -   MEM_STAT_REG(tmp,TYPE_VEC);
  6648. -   sp_mv_mlt(A,x,tmp);
  6649. -   sp_vm_mlt(A,tmp,out);
  6650. -   return out;
  6651. -
  6652. -}
  6653. -
  6654. -
  6655. -/* 
  6656. -  make symmetric preconditioner for nonsymmetric matrix A;
  6657. -   B = 0.5*(A+A^T) and then B is factorized using 
  6658. -   incomplete Choleski factorization
  6659. -*/
  6660. -
  6661. -SPMAT *gen_sym_precond(A)
  6662. -SPMAT *A;
  6663. -{
  6664. -   SPMAT *B;
  6665. -   SPROW *row;
  6666. -   int i,j,k;
  6667. -   Real val;
  6668. -   
  6669. -   B = sp_get(A->m,A->n,A->row[0].maxlen);
  6670. -   for (i=0; i < A->m; i++) {
  6671. -      row = &(A->row[i]);
  6672. -      for (j = 0; j < row->len; j++) {
  6673. -    k = row->elt[j].col;
  6674. -    if (i != k) {
  6675. -       val = 0.5*(sp_get_val(A,i,k) + sp_get_val(A,k,i));
  6676. -       sp_set_val(B,i,k,val);
  6677. -       sp_set_val(B,k,i,val);
  6678. -    }
  6679. -    else { /* i == k */
  6680. -      val = sp_get_val(A,i,i);
  6681. -      sp_set_val(B,i,i,val);
  6682. -       }
  6683. -     }
  6684. -   }
  6685. -
  6686. -   spICHfactor(B);
  6687. -   return B;
  6688. -}
  6689. -
  6690. -/* Dv_mlt -- diagonal by vector multiply; the diagonal matrix is represented
  6691. -        by a vector d */
  6692. -VEC    *Dv_mlt(d, x, out)
  6693. -VEC    *d, *x, *out;
  6694. -{
  6695. -    int        i;
  6696. -
  6697. -    if ( ! d || ! x )
  6698. -    error(E_NULL,"Dv_mlt");
  6699. -    if ( d->dim != x->dim )
  6700. -    error(E_SIZES,"Dv_mlt");
  6701. -    out = v_resize(out,x->dim);
  6702. -
  6703. -    for ( i = 0; i < x->dim; i++ )
  6704. -    out->ve[i] = d->ve[i]*x->ve[i];
  6705. -
  6706. -    return out;
  6707. -}
  6708. -
  6709. -
  6710. -
  6711. -/************************************************/
  6712. -void    main(argc, argv)
  6713. -int    argc;
  6714. -char    *argv[];
  6715. -{
  6716. -   VEC        *x, *y, *z, *u, *v, *xn, *yn;
  6717. -   SPMAT    *A = NULL, *B = NULL;
  6718. -   SPMAT    *An = NULL, *Bn = NULL;
  6719. -   int        i, k, kk, j;
  6720. -   ITER        *ips, *ips1, *ipns, *ipns1;
  6721. -   MAT         *Q, *H, *Q1, *H1;
  6722. -   VEC         vt, vt1;
  6723. -   Real        hh;
  6724. -
  6725. -
  6726. -   mem_info_on(TRUE);
  6727. -   notice("allocating sparse matrices");
  6728. -   
  6729. -   printf(" dim of A = %dx%d\n",ASYM,ASYM);
  6730. -   
  6731. -   A = iter_gen_sym(ASYM,8);   
  6732. -   B = sp_copy(A);
  6733. -   spICHfactor(B);
  6734. -   
  6735. -   u = v_get(A->n);
  6736. -   x = v_get(A->n);
  6737. -   y = v_get(A->n);
  6738. -   v = v_get(A->n);
  6739. -
  6740. -   v_rand(x);
  6741. -   sp_mv_mlt(A,x,y);
  6742. -   ex_sol = x;
  6743. -   
  6744. -   notice(" initialize ITER variables");
  6745. -   /* ips for symmetric matrices with precondition */
  6746. -   ips = iter_get(A->m,A->n);
  6747. -
  6748. -   /*  printf(" ips:\n");
  6749. -   iter_dump(stdout,ips);   */
  6750. -
  6751. -   ips->limit = 500;
  6752. -   ips->eps = EPS;
  6753. -   
  6754. -   iter_Ax(ips,sp_mv_mlt,A);
  6755. -   iter_Bx(ips,spCHsolve,B);
  6756. -
  6757. -   ips->b = v_copy(y,ips->b);
  6758. -   v_rand(ips->x);
  6759. -   /* test of iter_resize */
  6760. -   ips = iter_resize(ips,2*A->m,2*A->n);
  6761. -   ips = iter_resize(ips,A->m,A->n);
  6762. -
  6763. -   /*  printf(" ips:\n");
  6764. -   iter_dump(stdout,ips); */
  6765. -   
  6766. -   /* ips1 for symmetric matrices without precondition */
  6767. -   ips1 = iter_get(0,0);
  6768. -   /*   printf(" ips1:\n");
  6769. -   iter_dump(stdout,ips1);   */
  6770. -   ITER_FREE(ips1);
  6771. -
  6772. -   ips1 = iter_copy2(ips,ips1);
  6773. -   iter_Bx(ips1,NULL,NULL);
  6774. -   ips1->b = ips->b;
  6775. -   ips1->shared_b = TRUE;
  6776. -   /*    printf(" ips1:\n");
  6777. -   iter_dump(stdout,ips1);   */
  6778. -
  6779. -   /* ipns for nonsymetric matrices with precondition */
  6780. -   ipns = iter_copy(ips,INULL);
  6781. -   ipns->k = KK;
  6782. -   ipns->limit = 500;
  6783. -   ipns->info = NULL;
  6784. -
  6785. -   An = iter_gen_nonsym_posdef(ANON,8);   
  6786. -   Bn = gen_sym_precond(An);
  6787. -   xn = v_get(An->n);
  6788. -   yn = v_get(An->n);
  6789. -   v_rand(xn);
  6790. -   sp_mv_mlt(An,xn,yn);
  6791. -   ipns->b = v_copy(yn,ipns->b);
  6792. -
  6793. -   iter_Ax(ipns, sp_mv_mlt,An);
  6794. -   iter_ATx(ipns, sp_vm_mlt,An);
  6795. -   iter_Bx(ipns, spCHsolve,Bn);
  6796. -
  6797. -   /*  printf(" ipns:\n");
  6798. -   iter_dump(stdout,ipns); */
  6799. -   
  6800. -   /* ipns1 for nonsymmetric matrices without precondition */
  6801. -   ipns1 = iter_copy2(ipns,INULL);
  6802. -   ipns1->b = ipns->b;
  6803. -   ipns1->shared_b = TRUE;
  6804. -   iter_Bx(ipns1,NULL,NULL);
  6805. -
  6806. -   /*   printf(" ipns1:\n");
  6807. -   iter_dump(stdout,ipns1);  */
  6808. -
  6809. -
  6810. -   /*******  CG  ********/
  6811. -
  6812. -   notice(" CG method without preconditioning");
  6813. -   ips1->info = NULL;
  6814. -   mem_stat_mark(1);
  6815. -   iter_cg(ips1);
  6816. -
  6817. -   k = ips1->steps;
  6818. -   z = ips1->x;
  6819. -   printf(" cg: no. of iter.steps = %d\n",k);
  6820. -   v_sub(z,x,u);
  6821. -   printf(" (cg:) ||u_ex - u_approx||_2 = %g [EPS = %g]\n",
  6822. -      v_norm2(u),EPS);
  6823. -   
  6824. -   notice(" CG method with ICH preconditioning");
  6825. -
  6826. -   ips->info = NULL;
  6827. -   v_zero(ips->x);  
  6828. -   iter_cg(ips);  
  6829. -
  6830. -   k = ips->steps;
  6831. -   printf(" cg: no. of iter.steps = %d\n",k);
  6832. -   v_sub(ips->x,x,u);
  6833. -   printf(" (cg:) ||u_ex - u_approx||_2 = %g [EPS = %g]\n",
  6834. -      v_norm2(u),EPS);
  6835. -   
  6836. -   V_FREE(v);
  6837. -   if ((v = iter_spcg(A,B,y,EPS,VNULL,1000,&k)) == VNULL)
  6838. -     errmesg("CG method with precond.: NULL solution"); 
  6839. -   
  6840. -   v_sub(ips->x,v,u);
  6841. -   if (v_norm2(u) >= EPS) {
  6842. -      errmesg("CG method with precond.: different solutions");
  6843. -      printf(" diff. = %g\n",v_norm2(u));
  6844. -   }   
  6845. -   
  6846. -
  6847. -   mem_stat_free(1);
  6848. -   printf(" spcg: # of iter. steps = %d\n",k);
  6849. -   v_sub(v,x,u);
  6850. -   printf(" (spcg:) ||u_ex - u_approx||_2 = %g  [EPS = %g]\n",
  6851. -      v_norm2(u),EPS);  
  6852. -
  6853. -
  6854. -   /***  CG FOR NORMAL EQUATION *****/
  6855. -
  6856. -   notice("CGNE method with ICH preconditioning (nonsymmetric case)");
  6857. -
  6858. -   /* ipns->info = iter_std_info;  */
  6859. -   ipns->info = NULL;
  6860. -   v_zero(ipns->x);
  6861. -   mem_stat_mark(1);
  6862. -   iter_cgne(ipns);
  6863. -
  6864. -   k = ipns->steps;
  6865. -   z = ipns->x;
  6866. -   printf(" cgne: no. of iter.steps = %d\n",k);
  6867. -   v_sub(z,xn,u);
  6868. -   printf(" (cgne:) ||u_ex - u_approx||_2 = %g  [EPS = %g]\n",
  6869. -      v_norm2(u),EPS);
  6870. -
  6871. -   notice("CGNE method without preconditioning (nonsymmetric case)");
  6872. -
  6873. -   v_rand(u);
  6874. -   u = iter_spcgne(An,NULL,yn,EPS,u,1000,&k);
  6875. -
  6876. -   mem_stat_free(1);
  6877. -   printf(" spcgne: no. of iter.steps = %d\n",k);
  6878. -   v_sub(u,xn,u);
  6879. -   printf(" (spcgne:) ||u_ex - u_approx||_2 = %g  [EPS = %g]\n",
  6880. -      v_norm2(u),EPS);
  6881. -
  6882. -   /***  CGS  *****/
  6883. -
  6884. -   notice("CGS method with ICH preconditioning (nonsymmetric case)");
  6885. -
  6886. -   v_zero(ipns->x);   /* new init guess == 0 */
  6887. -   mem_stat_mark(1);
  6888. -   ipns->info = NULL;
  6889. -   v_rand(u);
  6890. -   iter_cgs(ipns,u);
  6891. -
  6892. -   k = ipns->steps;
  6893. -   z = ipns->x;
  6894. -   printf(" cgs: no. of iter.steps = %d\n",k);
  6895. -   v_sub(z,xn,u);
  6896. -   printf(" (cgs:) ||u_ex - u_approx||_2 = %g  [EPS = %g]\n",
  6897. -      v_norm2(u),EPS);
  6898. -
  6899. -   notice("CGS method without preconditioning (nonsymmetric case)");
  6900. -
  6901. -   v_rand(u);
  6902. -   v_rand(v);
  6903. -   v = iter_spcgs(An,NULL,yn,u,EPS,v,1000,&k);
  6904. -
  6905. -   mem_stat_free(1);
  6906. -   printf(" cgs: no. of iter.steps = %d\n",k);
  6907. -   v_sub(v,xn,u);
  6908. -   printf(" (cgs:) ||u_ex - u_approx||_2 = %g  [EPS = %g]\n",
  6909. -      v_norm2(u),EPS);
  6910. -   
  6911. -
  6912. -
  6913. -   /*** LSQR ***/
  6914. -
  6915. -   notice("LSQR method (without preconditioning)");
  6916. -
  6917. -   v_rand(u);
  6918. -   v_free(ipns1->x);
  6919. -   ipns1->x = u;
  6920. -   ipns1->shared_x = TRUE;
  6921. -   ipns1->info = NULL;
  6922. -   mem_stat_mark(2);
  6923. -   z = iter_lsqr(ipns1);
  6924. -   
  6925. -   v_sub(xn,z,v);
  6926. -   k = ipns1->steps;
  6927. -   printf(" lsqr: # of iter. steps = %d\n",k);
  6928. -   printf(" (lsqr:) ||u_ex - u_approx||_2 = %g  [EPS = %g]\n",
  6929. -      v_norm2(v),EPS);
  6930. -
  6931. -   v_rand(u);
  6932. -   u = iter_splsqr(An,yn,EPS,u,1000,&k);
  6933. -   mem_stat_free(2);
  6934. -   
  6935. -   v_sub(xn,u,v);
  6936. -   printf(" splsqr: # of iter. steps = %d\n",k);
  6937. -   printf(" (splsqr:) ||u_ex - u_approx||_2 = %g [EPS = %g]\n",    
  6938. -      v_norm2(v),EPS);
  6939. -
  6940. -
  6941. -
  6942. -   /***** GMRES ********/
  6943. -
  6944. -   notice("GMRES method with ICH preconditioning (nonsymmetric case)");
  6945. -
  6946. -   v_zero(ipns->x);
  6947. -/*   ipns->info = iter_std_info;  */
  6948. -   ipns->info = NULL;  
  6949. -
  6950. -   mem_stat_mark(2);
  6951. -   z = iter_gmres(ipns);
  6952. -   v_sub(xn,z,v);
  6953. -   k = ipns->steps;
  6954. -   printf(" gmres: # of iter. steps = %d\n",k);
  6955. -   printf(" (gmres:) ||u_ex - u_approx||_2 = %g  [EPS = %g]\n",
  6956. -      v_norm2(v),EPS);
  6957. -
  6958. -   notice("GMRES method without preconditioning (nonsymmetric case)");
  6959. -   V_FREE(v);
  6960. -   v = iter_spgmres(An,NULL,yn,EPS,VNULL,10,1004,&k);
  6961. -   mem_stat_free(2);
  6962. -   
  6963. -   v_sub(xn,v,v);
  6964. -   printf(" spgmres: # of iter. steps = %d\n",k);
  6965. -   printf(" (spgmres:) ||u_ex - u_approx||_2 = %g  [EPS = %g]\n",
  6966. -      v_norm2(v),EPS);
  6967. -
  6968. -
  6969. -
  6970. -   /**** MGCR *****/
  6971. -
  6972. -   notice("MGCR method with ICH preconditioning (nonsymmetric case)");
  6973. -
  6974. -   v_zero(ipns->x);
  6975. -   mem_stat_mark(2);
  6976. -   z = iter_mgcr(ipns);
  6977. -   v_sub(xn,z,v);
  6978. -   k = ipns->steps;
  6979. -   printf(" mgcr: # of iter. steps = %d\n",k);
  6980. -   printf(" (mgcr:) ||u_ex - u_approx||_2 = %g  [EPS = %g]\n",
  6981. -      v_norm2(v),EPS);
  6982. -
  6983. -   notice("MGCR method without  preconditioning (nonsymmetric case)");
  6984. -   V_FREE(v);
  6985. -   v = iter_spmgcr(An,NULL,yn,EPS,VNULL,10,1004,&k);
  6986. -   mem_stat_free(2);
  6987. -   
  6988. -   v_sub(xn,v,v);
  6989. -   printf(" spmgcr: # of iter. steps = %d\n",k);
  6990. -   printf(" (spmgcr:) ||u_ex - u_approx||_2 = %g [EPS = %g]\n",
  6991. -      v_norm2(v),EPS);
  6992. -
  6993. -
  6994. -   /***** ARNOLDI METHOD ********/
  6995. -
  6996. -
  6997. -   notice("arnoldi method");
  6998. -
  6999. -   kk = ipns1->k = KK;
  7000. -   Q = m_get(kk,x->dim);
  7001. -   Q1 = m_get(kk,x->dim);
  7002. -   H = m_get(kk,kk);
  7003. -   v_rand(u);
  7004. -   ipns1->x = u;
  7005. -   ipns1->shared_x = TRUE;
  7006. -   mem_stat_mark(3);
  7007. -   iter_arnoldi_iref(ipns1,&hh,Q,H);
  7008. -   mem_stat_free(3);
  7009. -
  7010. -   /* check the equality:
  7011. -      Q*A*Q^T = H; */
  7012. -
  7013. -   vt.dim = vt.max_dim = x->dim;
  7014. -   vt1.dim = vt1.max_dim = x->dim;
  7015. -   for (j=0; j < kk; j++) {
  7016. -      vt.ve = Q->me[j];
  7017. -      vt1.ve = Q1->me[j];
  7018. -      sp_mv_mlt(An,&vt,&vt1);
  7019. -   }
  7020. -   H1 = m_get(kk,kk);
  7021. -   mmtr_mlt(Q,Q1,H1);
  7022. -   m_sub(H,H1,H1);
  7023. -   if (m_norm_inf(H1) > MACHEPS*x->dim)
  7024. -     printf(" (arnoldi_iref) ||Q*A*Q^T - H|| = %g [cf. MACHEPS = %g]\n",
  7025. -        m_norm_inf(H1),MACHEPS);
  7026. -
  7027. -   /* check Q*Q^T = I  */
  7028. -
  7029. -   mmtr_mlt(Q,Q,H1);
  7030. -   for (j=0; j < kk; j++)
  7031. -     H1->me[j][j] -= 1.0;
  7032. -   if (m_norm_inf(H1) > MACHEPS*x->dim)
  7033. -     printf(" (arnoldi_iref) ||Q*Q^T - I|| = %g [cf. MACHEPS = %g]\n",
  7034. -        m_norm_inf(H1),MACHEPS);
  7035. -
  7036. -   ipns1->x = u;
  7037. -   ipns1->shared_x = TRUE;
  7038. -   mem_stat_mark(3);
  7039. -   iter_arnoldi(ipns1,&hh,Q,H);
  7040. -   mem_stat_free(3);
  7041. -
  7042. -   /* check the equality:
  7043. -      Q*A*Q^T = H; */
  7044. -
  7045. -   vt.dim = vt.max_dim = x->dim;
  7046. -   vt1.dim = vt1.max_dim = x->dim;
  7047. -   for (j=0; j < kk; j++) {
  7048. -      vt.ve = Q->me[j];
  7049. -      vt1.ve = Q1->me[j];
  7050. -      sp_mv_mlt(An,&vt,&vt1);
  7051. -   }
  7052. -
  7053. -   mmtr_mlt(Q,Q1,H1);
  7054. -   m_sub(H,H1,H1);
  7055. -  if (m_norm_inf(H1) > MACHEPS*x->dim)  
  7056. -     printf(" (arnoldi) ||Q*A*Q^T - H|| = %g [cf. MACHEPS = %g]\n",
  7057. -        m_norm_inf(H1),MACHEPS);
  7058. -   /* check Q*Q^T = I  */
  7059. -   mmtr_mlt(Q,Q,H1);
  7060. -   for (j=0; j < kk; j++)
  7061. -     H1->me[j][j] -= 1.0;
  7062. -   if (m_norm_inf(H1) > MACHEPS*x->dim)
  7063. -     printf(" (arnoldi) ||Q*Q^T - I|| = %g [cf. MACHEPS = %g]\n",
  7064. -        m_norm_inf(H1),MACHEPS);
  7065. -
  7066. -   v_rand(u);
  7067. -   mem_stat_mark(3);
  7068. -   iter_sparnoldi(An,u,kk,&hh,Q,H);
  7069. -   mem_stat_free(3);
  7070. -
  7071. -   /* check the equality:
  7072. -      Q*A*Q^T = H; */
  7073. -
  7074. -   vt.dim = vt.max_dim = x->dim;
  7075. -   vt1.dim = vt1.max_dim = x->dim;
  7076. -   for (j=0; j < kk; j++) {
  7077. -      vt.ve = Q->me[j];
  7078. -      vt1.ve = Q1->me[j];
  7079. -      sp_mv_mlt(An,&vt,&vt1);
  7080. -   }
  7081. -
  7082. -   mmtr_mlt(Q,Q1,H1);
  7083. -   m_sub(H,H1,H1);
  7084. -   if (m_norm_inf(H1) > MACHEPS*x->dim)
  7085. -     printf(" (sparnoldi) ||Q*A*Q^T - H|| = %g [cf. MACHEPS = %g]\n",
  7086. -        m_norm_inf(H1),MACHEPS);
  7087. -   /* check Q*Q^T = I  */
  7088. -   mmtr_mlt(Q,Q,H1);
  7089. -   for (j=0; j < kk; j++)
  7090. -     H1->me[j][j] -= 1.0;
  7091. -   if (m_norm_inf(H1) > MACHEPS*x->dim)
  7092. -     printf(" (sparnoldi) ||Q*Q^T - I|| = %g [cf. MACHEPS = %g]\n",
  7093. -        m_norm_inf(H1),MACHEPS);
  7094. -
  7095. -
  7096. -
  7097. -   /****** LANCZOS METHOD ******/
  7098. -
  7099. -   notice("lanczos method");
  7100. -   kk = ipns1->k; 
  7101. -   Q = m_resize(Q,kk,x->dim);
  7102. -   Q1 = m_resize(Q1,kk,x->dim);
  7103. -   H = m_resize(H,kk,kk);
  7104. -   ips1->k = kk;
  7105. -   v_rand(u);
  7106. -   v_free(ips1->x);
  7107. -   ips1->x = u;
  7108. -   ips1->shared_x = TRUE;
  7109. -
  7110. -   mem_stat_mark(3);
  7111. -   iter_lanczos(ips1,x,y,&hh,Q);
  7112. -   mem_stat_free(3);
  7113. -
  7114. -   /* check the equality:
  7115. -      Q*A*Q^T = H; */
  7116. -
  7117. -   vt.dim = vt1.dim = Q->n;
  7118. -   vt.max_dim = vt1.max_dim = Q->max_n;
  7119. -   Q1 = m_resize(Q1,Q->m,Q->n);
  7120. -   for (j=0; j < Q->m; j++) {
  7121. -      vt.ve = Q->me[j];
  7122. -      vt1.ve = Q1->me[j];
  7123. -      sp_mv_mlt(A,&vt,&vt1);
  7124. -   }
  7125. -   H1 = m_resize(H1,Q->m,Q->m);
  7126. -   H = m_resize(H,Q->m,Q->m);
  7127. -   mmtr_mlt(Q,Q1,H1);
  7128. -
  7129. -   m_zero(H);
  7130. -   for (j=0; j < Q->m-1; j++) {
  7131. -      H->me[j][j] = x->ve[j];
  7132. -      H->me[j][j+1] = H->me[j+1][j] = y->ve[j];
  7133. -   }
  7134. -   H->me[Q->m-1][Q->m-1] = x->ve[Q->m-1];
  7135. -
  7136. -   m_sub(H,H1,H1);
  7137. -   if (m_norm_inf(H1) > MACHEPS*x->dim)
  7138. -     printf(" (lanczos) ||Q*A*Q^T - H|| = %g [cf. MACHEPS = %g]\n",
  7139. -        m_norm_inf(H1),MACHEPS);
  7140. -
  7141. -   /* check Q*Q^T = I  */
  7142. -
  7143. -   mmtr_mlt(Q,Q,H1);
  7144. -   for (j=0; j < Q->m; j++)
  7145. -     H1->me[j][j] -= 1.0;
  7146. -   if (m_norm_inf(H1) > MACHEPS*x->dim)
  7147. -     printf(" (lanczos) ||Q*Q^T - I|| = %g [cf. MACHEPS = %g]\n",
  7148. -        m_norm_inf(H1),MACHEPS);
  7149. -
  7150. -   mem_stat_mark(3);
  7151. -   v_rand(u);
  7152. -   iter_splanczos(A,kk,u,x,y,&hh,Q);
  7153. -   mem_stat_free(3);
  7154. -
  7155. -   /* check the equality:
  7156. -      Q*A*Q^T = H; */
  7157. -
  7158. -   vt.dim = vt1.dim = Q->n;
  7159. -   vt.max_dim = vt1.max_dim = Q->max_n;
  7160. -   Q1 = m_resize(Q1,Q->m,Q->n);
  7161. -   for (j=0; j < Q->m; j++) {
  7162. -      vt.ve = Q->me[j];
  7163. -      vt1.ve = Q1->me[j];
  7164. -      sp_mv_mlt(A,&vt,&vt1);
  7165. -   }
  7166. -   H1 = m_resize(H1,Q->m,Q->m);
  7167. -   H = m_resize(H,Q->m,Q->m);
  7168. -   mmtr_mlt(Q,Q1,H1);
  7169. -   for (j=0; j < Q->m-1; j++) {
  7170. -      H->me[j][j] = x->ve[j];
  7171. -      H->me[j][j+1] = H->me[j+1][j] = y->ve[j];
  7172. -   }
  7173. -   H->me[Q->m-1][Q->m-1] = x->ve[Q->m-1];
  7174. -
  7175. -   m_sub(H,H1,H1);
  7176. -   if (m_norm_inf(H1) > MACHEPS*x->dim)
  7177. -     printf(" (splanczos) ||Q*A*Q^T - H|| = %g [cf. MACHEPS = %g]\n",
  7178. -        m_norm_inf(H1),MACHEPS);
  7179. -   /* check Q*Q^T = I  */
  7180. -   mmtr_mlt(Q,Q,H1);
  7181. -   for (j=0; j < Q->m; j++)
  7182. -     H1->me[j][j] -= 1.0;
  7183. -   if (m_norm_inf(H1) > MACHEPS*x->dim)
  7184. -     printf(" (splanczos) ||Q*Q^T - I|| = %g [cf. MACHEPS = %g]\n",
  7185. -        m_norm_inf(H1),MACHEPS);
  7186. -
  7187. -
  7188. -
  7189. -   /***** LANCZOS2 ****/
  7190. -
  7191. -   notice("lanczos2 method");
  7192. -   kk = 50;          /* # of dir. vectors */
  7193. -   ips1->k = kk;
  7194. -   v_rand(u);
  7195. -   ips1->x = u;
  7196. -   ips1->shared_x = TRUE;
  7197. -
  7198. -   for ( i = 0; i < xn->dim; i++ )
  7199. -    xn->ve[i] = i;
  7200. -   iter_Ax(ips1,Dv_mlt,xn);
  7201. -   mem_stat_mark(3);
  7202. -   iter_lanczos2(ips1,y,v);
  7203. -   mem_stat_free(3);
  7204. -
  7205. -   printf("# Number of steps of Lanczos algorithm = %d\n", kk);
  7206. -   printf("# Exact eigenvalues are 0, 1, 2, ..., %d\n",ANON-1);
  7207. -   printf("# Extreme eigenvalues should be accurate; \n");
  7208. -   printf("# interior values usually are not.\n");
  7209. -   printf("# approx e-vals =\n");    v_output(y);
  7210. -   printf("# Error in estimate of bottom e-vec (Lanczos) = %g\n",
  7211. -      fabs(v->ve[0]));
  7212. -
  7213. -   mem_stat_mark(3);
  7214. -   v_rand(u);
  7215. -   iter_splanczos2(A,kk,u,y,v);
  7216. -   mem_stat_free(3);
  7217. -
  7218. -
  7219. -   /***** FINISHING *******/
  7220. -
  7221. -   notice("release ITER variables");
  7222. -   
  7223. -   M_FREE(Q);
  7224. -   M_FREE(Q1);
  7225. -   M_FREE(H);
  7226. -   M_FREE(H1);
  7227. -
  7228. -   ITER_FREE(ipns);
  7229. -   ITER_FREE(ips);
  7230. -   ITER_FREE(ipns1);
  7231. -   ITER_FREE(ips1);
  7232. -   SP_FREE(A);
  7233. -   SP_FREE(B);
  7234. -   SP_FREE(An);
  7235. -   SP_FREE(Bn);
  7236. -   
  7237. -   V_FREE(x);
  7238. -   V_FREE(y);
  7239. -   V_FREE(u);
  7240. -   V_FREE(v); 
  7241. -   V_FREE(xn);
  7242. -   V_FREE(yn);
  7243. -
  7244. -   printf("# Done testing (%s)\n",argv[0]);
  7245. -   mem_info();
  7246. -}
  7247. //GO.SYSIN DD itertort.c
  7248. echo mfuntort.c 1>&2
  7249. sed >mfuntort.c <<'//GO.SYSIN DD mfuntort.c' 's/^-//'
  7250. -
  7251. -/**************************************************************************
  7252. -**
  7253. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  7254. -**
  7255. -**                 Meschach Library
  7256. -** 
  7257. -** This Meschach Library is provided "as is" without any express 
  7258. -** or implied warranty of any kind with respect to this software. 
  7259. -** In particular the authors shall not be liable for any direct, 
  7260. -** indirect, special, incidental or consequential damages arising 
  7261. -** in any way from use of the software.
  7262. -** 
  7263. -** Everyone is granted permission to copy, modify and redistribute this
  7264. -** Meschach Library, provided:
  7265. -**  1.  All copies contain this copyright notice.
  7266. -**  2.  All modified copies shall carry a notice stating who
  7267. -**      made the last modification and the date of such modification.
  7268. -**  3.  No charge is made for this software or works derived from it.  
  7269. -**      This clause shall not be construed as constraining other software
  7270. -**      distributed on the same medium as this software, nor is a
  7271. -**      distribution fee considered a charge.
  7272. -**
  7273. -***************************************************************************/
  7274. -
  7275. -
  7276. -/* mfuntort.c,  10/11/93 */
  7277. -
  7278. -static char rcsid[] = "$Id: mfuntort.c,v 1.2 1994/01/14 01:08:06 des Exp $";
  7279. -
  7280. -#include        <stdio.h>
  7281. -#include        <math.h>
  7282. -#include        "matrix.h"
  7283. -#include        "matrix2.h"
  7284. -
  7285. -
  7286. -#define errmesg(mesg)   printf("Error: %s error: line %d\n",mesg,__LINE__)
  7287. -#define notice(mesg)    printf("# Testing %s...\n",mesg);
  7288. -
  7289. -#define DIM  10
  7290. -
  7291. -void main()
  7292. -{
  7293. -
  7294. -   MAT *A, *B, *C, *OUTA, *OUTB, *TMP;
  7295. -   MAT *exp_A_expected, *exp_A;
  7296. -   VEC *x, *b;
  7297. -   double c, eps = 1e-10;
  7298. -   int i, j, q_out, j_out;
  7299. -
  7300. -   mem_info_on(TRUE);
  7301. -
  7302. -   A = m_get(DIM,DIM);
  7303. -   B = m_get(DIM,DIM);
  7304. -   C = m_get(DIM,DIM);
  7305. -   OUTA = m_get(DIM,DIM);
  7306. -   OUTB = m_get(DIM,DIM);
  7307. -   TMP = m_get(DIM,DIM);
  7308. -   x = v_get(DIM);
  7309. -   b = v_get(6);
  7310. -
  7311. -   notice("exponent of a matrix");
  7312. -
  7313. -   m_ident(A);
  7314. -   mem_stat_mark(1);
  7315. -   _m_exp(A,eps,OUTA,&q_out,&j_out);
  7316. -   printf("# q_out = %d, j_out = %d\n",q_out,j_out);
  7317. -
  7318. -   m_exp(A,eps,OUTA);
  7319. -   sm_mlt(exp(1.0),A,A);
  7320. -   m_sub(OUTA,A,TMP);
  7321. -   printf("# ||exp(I) - e*I|| = %g\n",m_norm_inf(TMP));
  7322. -
  7323. -   m_rand(A);
  7324. -   m_transp(A,TMP);
  7325. -   m_add(A,TMP,A);
  7326. -   B = m_copy(A,B);
  7327. -
  7328. -   m_exp(A,eps,OUTA);
  7329. -
  7330. -   symmeig(B,OUTB,x);
  7331. -   m_zero(TMP);
  7332. -   for (i=0; i < x->dim; i++)
  7333. -     TMP->me[i][i] = exp(x->ve[i]);
  7334. -   m_mlt(OUTB,TMP,C);
  7335. -   mmtr_mlt(C,OUTB,TMP);
  7336. -   m_sub(TMP,OUTA,TMP);
  7337. -   printf("# ||exp(A) - Q*exp(lambda)*Q^T|| = %g\n",m_norm_inf(TMP));
  7338. -
  7339. -   notice("polynomial of a matrix");
  7340. -   m_rand(A);
  7341. -   m_transp(A,TMP);
  7342. -   m_add(A,TMP,A);
  7343. -   B = m_copy(A,B);
  7344. -   v_rand(b);
  7345. -
  7346. -   m_poly(A,b,OUTA);
  7347. -
  7348. -   symmeig(B,OUTB,x);
  7349. -   m_zero(TMP);
  7350. -   for (i=0; i < x->dim; i++) {
  7351. -      c = b->ve[b->dim-1];
  7352. -      for (j=b->dim-2; j >= 0; j--) 
  7353. -    c = c*x->ve[i] + b->ve[j];
  7354. -      TMP->me[i][i] = c;
  7355. -   }
  7356. -   m_mlt(OUTB,TMP,C);
  7357. -   mmtr_mlt(C,OUTB,TMP);
  7358. -   m_sub(TMP,OUTA,TMP);
  7359. -   printf("# ||poly(A) - Q*poly(lambda)*Q^T|| = %g\n",m_norm_inf(TMP));
  7360. -   mem_stat_free(1);
  7361. -
  7362. -
  7363. -   /* Brook Milligan's test */
  7364. -
  7365. -   M_FREE(A);
  7366. -   M_FREE(B);
  7367. -   M_FREE(C);
  7368. -
  7369. -   notice("exponent of a nonsymmetric matrix");
  7370. -   A = m_get (2, 2);
  7371. -   A -> me [0][0] = 1.0;
  7372. -   A -> me [0][1] = 1.0;
  7373. -   A -> me [1][0] = 4.0;
  7374. -   A -> me [1][1] = 1.0;
  7375. -   
  7376. -   exp_A_expected = m_get(2, 2);
  7377. -   exp_A_expected -> me [0][0] = exp (3.0) / 2.0 + exp (-1.0) / 2.0;
  7378. -   exp_A_expected -> me [0][1] = exp (3.0) / 4.0 - exp (-1.0) / 4.0;
  7379. -   exp_A_expected -> me [1][0] = exp (3.0)       - exp (-1.0);
  7380. -   exp_A_expected -> me [1][1] = exp (3.0) / 2.0 + exp (-1.0) / 2.0;
  7381. -   
  7382. -   printf ("A:\n");
  7383. -   for (i = 0; i < 2; i++)
  7384. -   {
  7385. -      for (j = 0; j < 2; j++)
  7386. -        printf ("   %15.8e", A -> me [i][j]);
  7387. -      printf ("\n");
  7388. -   }
  7389. -   
  7390. -   printf ("\nexp(A) (expected):\n");
  7391. -   for (i = 0; i < 2; i++)
  7392. -   {
  7393. -      for (j = 0; j < 2; j++)
  7394. -        printf ("   %15.8e", exp_A_expected -> me [i][j]);
  7395. -      printf ("\n");
  7396. -   }
  7397. -   
  7398. -   mem_stat_mark(3);
  7399. -   exp_A = m_exp (A, 1e-16,NULL);
  7400. -   mem_stat_free(3);
  7401. -
  7402. -   printf ("\nexp(A):\n");
  7403. -   for (i = 0; i < 2; i++)
  7404. -   {
  7405. -      for (j = 0; j < 2; j++)
  7406. -        printf ("   %15.8e", exp_A -> me [i][j]);
  7407. -      printf ("\n");
  7408. -   }
  7409. -   printf ("\nexp(A) - exp(A) (expected):\n");
  7410. -   for (i = 0; i < 2; i++)
  7411. -   {
  7412. -      for (j = 0; j < 2; j++)
  7413. -        printf ("   %15.8e", exp_A -> me [i][j] - exp_A_expected -> me [i][j]);
  7414. -      printf ("\n");
  7415. -   }
  7416. -
  7417. -   M_FREE(A);
  7418. -   M_FREE(B);
  7419. -   M_FREE(C);
  7420. -   M_FREE(exp_A);
  7421. -   M_FREE(exp_A_expected);
  7422. -   M_FREE(OUTA);
  7423. -   M_FREE(OUTB);
  7424. -   M_FREE(TMP);
  7425. -   V_FREE(b);
  7426. -   V_FREE(x);
  7427. -
  7428. -   mem_info();
  7429. -}
  7430. -
  7431. //GO.SYSIN DD mfuntort.c
  7432. echo iotort.c 1>&2
  7433. sed >iotort.c <<'//GO.SYSIN DD iotort.c' 's/^-//'
  7434. -
  7435. -/**************************************************************************
  7436. -**
  7437. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  7438. -**
  7439. -**                 Meschach Library
  7440. -** 
  7441. -** This Meschach Library is provided "as is" without any express 
  7442. -** or implied warranty of any kind with respect to this software. 
  7443. -** In particular the authors shall not be liable for any direct, 
  7444. -** indirect, special, incidental or consequential damages arising 
  7445. -** in any way from use of the software.
  7446. -** 
  7447. -** Everyone is granted permission to copy, modify and redistribute this
  7448. -** Meschach Library, provided:
  7449. -**  1.  All copies contain this copyright notice.
  7450. -**  2.  All modified copies shall carry a notice stating who
  7451. -**      made the last modification and the date of such modification.
  7452. -**  3.  No charge is made for this software or works derived from it.  
  7453. -**      This clause shall not be construed as constraining other software
  7454. -**      distributed on the same medium as this software, nor is a
  7455. -**      distribution fee considered a charge.
  7456. -**
  7457. -***************************************************************************/
  7458. -
  7459. -/* iotort.c  10/11/93 */
  7460. -/* test of I/O functions */
  7461. -
  7462. -
  7463. -static char rcsid[] = "$Id: $";
  7464. -
  7465. -#include "sparse.h"
  7466. -#include "zmatrix.h"
  7467. -
  7468. -
  7469. -#define    errmesg(mesg)    printf("Error: %s error: line %d\n",mesg,__LINE__)
  7470. -#define notice(mesg)    printf("# Testing %s...\n",mesg);
  7471. -
  7472. -
  7473. -void main()
  7474. -{
  7475. -   VEC *x;
  7476. -   MAT *A;
  7477. -   PERM *pivot;
  7478. -   IVEC *ix;
  7479. -   SPMAT *spA;
  7480. -   ZVEC *zx;
  7481. -   ZMAT *ZA;
  7482. -   char yes;
  7483. -   int i;
  7484. -   FILE *fp;
  7485. -
  7486. -   mem_info_on(TRUE);
  7487. -
  7488. -   if ((fp = fopen("iotort.dat","w")) == NULL) {
  7489. -      printf(" !!! Cannot open file %s for writing\n\n","iotort.dat");
  7490. -      exit(1);
  7491. -   }
  7492. -     
  7493. -   x = v_get(10);
  7494. -   A = m_get(3,3);
  7495. -   zx = zv_get(10);
  7496. -   ZA = zm_get(3,3);
  7497. -   pivot = px_get(10);
  7498. -   ix = iv_get(10);
  7499. -   spA = sp_get(3,3,2);
  7500. -
  7501. -   v_rand(x);
  7502. -   m_rand(A);
  7503. -   zv_rand(zx);
  7504. -   zm_rand(ZA);
  7505. -   px_ident(pivot);
  7506. -   for (i=0; i < 10; i++)
  7507. -     ix->ive[i] = i+1;
  7508. -   for (i=0; i < spA->m; i++) {
  7509. -      sp_set_val(spA,i,i,1.0);
  7510. -      if (i > 0) sp_set_val(spA,i-1,i,-1.0);
  7511. -   }
  7512. -
  7513. -   notice(" VEC output");
  7514. -   v_foutput(fp,x);
  7515. -   notice(" MAT output");
  7516. -   m_foutput(fp,A);
  7517. -   notice(" ZVEC output");
  7518. -   zv_foutput(fp,zx);
  7519. -   notice(" ZMAT output");
  7520. -   zm_foutput(fp,ZA);
  7521. -   notice(" PERM output");
  7522. -   px_foutput(fp,pivot);
  7523. -   notice(" IVEC output");
  7524. -   iv_foutput(fp,ix);
  7525. -   notice(" SPMAT output");
  7526. -   sp_foutput(fp,spA);
  7527. -   fprintf(fp,"Y");
  7528. -   fclose(fp);
  7529. -
  7530. -   printf("\nENTER SOME VALUES:\n\n");
  7531. -
  7532. -   if ((fp = fopen("iotort.dat","r")) == NULL) {
  7533. -      printf(" !!! Cannot open file %s for reading\n\n","iotort.dat");
  7534. -      exit(1);
  7535. -   }
  7536. -
  7537. -   notice(" VEC input/output");
  7538. -   x = v_finput(fp,x);
  7539. -   v_output(x);
  7540. -
  7541. -   notice(" MAT input/output");
  7542. -   A = m_finput(fp,A);
  7543. -   m_output(A);
  7544. -
  7545. -   notice(" ZVEC input/output");
  7546. -   zx = zv_finput(fp,zx);
  7547. -   zv_output(zx);
  7548. -
  7549. -   notice(" ZMAT input/output");
  7550. -   ZA = zm_finput(fp,ZA);
  7551. -   zm_output(ZA);
  7552. -
  7553. -   notice(" PERM input/output");
  7554. -   pivot = px_finput(fp,pivot);
  7555. -   px_output(pivot);
  7556. -
  7557. -   notice(" IVEC input/output");
  7558. -   ix = iv_finput(fp,ix);
  7559. -   iv_output(ix);
  7560. -
  7561. -   notice(" SPMAT input/output");
  7562. -   SP_FREE(spA);
  7563. -   spA = sp_finput(fp);
  7564. -   sp_output(spA);
  7565. -
  7566. -   notice(" general input");
  7567. -   finput(fp," finish the test?  ","%c",&yes);
  7568. -   if (yes == 'y' || yes == 'Y' )
  7569. -     printf(" YES\n");
  7570. -   else printf(" NO\n");
  7571. -   fclose(fp);
  7572. -
  7573. -   mem_info();
  7574. -}
  7575. //GO.SYSIN DD iotort.c
  7576. echo err.h 1>&2
  7577. sed >err.h <<'//GO.SYSIN DD err.h' 's/^-//'
  7578. -
  7579. -/**************************************************************************
  7580. -**
  7581. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  7582. -**
  7583. -**                 Meschach Library
  7584. -** 
  7585. -** This Meschach Library is provided "as is" without any express 
  7586. -** or implied warranty of any kind with respect to this software. 
  7587. -** In particular the authors shall not be liable for any direct, 
  7588. -** indirect, special, incidental or consequential damages arising 
  7589. -** in any way from use of the software.
  7590. -** 
  7591. -** Everyone is granted permission to copy, modify and redistribute this
  7592. -** Meschach Library, provided:
  7593. -**  1.  All copies contain this copyright notice.
  7594. -**  2.  All modified copies shall carry a notice stating who
  7595. -**      made the last modification and the date of such modification.
  7596. -**  3.  No charge is made for this software or works derived from it.  
  7597. -**      This clause shall not be construed as constraining other software
  7598. -**      distributed on the same medium as this software, nor is a
  7599. -**      distribution fee considered a charge.
  7600. -**
  7601. -***************************************************************************/
  7602. -
  7603. -
  7604. -/* err.h  28/09/1993 */
  7605. -
  7606. -/*  RCS id: $Id: err.h,v 1.1 1994/01/13 05:38:03 des Exp $  */
  7607. -
  7608. -
  7609. -#ifndef ERRHEADER
  7610. -#define ERRHEADER
  7611. -
  7612. -
  7613. -#include        <setjmp.h>
  7614. -#include        "machine.h"
  7615. -
  7616. -/* Error recovery */
  7617. -
  7618. -extern    jmp_buf    restart;
  7619. -
  7620. -
  7621. -/* max. # of error lists */
  7622. -#define ERR_LIST_MAX_LEN   10
  7623. -
  7624. -/* main error functions */
  7625. -#ifndef ANSI_C
  7626. -extern    int ev_err();            /* main error handler */
  7627. -extern    int set_err_flag();        /* for different ways of handling
  7628. -                                                errors, returns old value */
  7629. -extern  int count_errs();        /* to avoid "too many errors" */
  7630. -extern  int err_list_attach();        /* for attaching a list of errors */
  7631. -extern  int err_is_list_attached();    /* checking if a list is attached */
  7632. -extern  int err_list_free();        /* freeing a list of errors */
  7633. -
  7634. -#else  /* ANSI_C */
  7635. -
  7636. -extern    int ev_err(char *,int,int,char *,int);  /* main error handler */
  7637. -extern    int set_err_flag(int flag);         /* for different ways of handling
  7638. -                                                errors, returns old value */
  7639. -extern  int count_errs(int true_false);     /* to avoid "too many errors" */
  7640. -extern  int err_list_attach(int list_num, int list_len,
  7641. -           char **err_ptr,int warn);  /* for attaching a list of errors */
  7642. -extern  int err_is_list_attached(int list_num);  /* checking if a list 
  7643. -                            is attached */
  7644. -extern  int err_list_free(int list_num);   /* freeing a list of errors */
  7645. -
  7646. -#endif
  7647. -
  7648. -
  7649. -/* error(E_TYPE,"myfunc") raises error type E_TYPE for function my_func() */
  7650. -#define    error(err_num,fn_name)    ev_err(__FILE__,err_num,__LINE__,fn_name,0)
  7651. -
  7652. -/* warning(WARN_TYPE,"myfunc") raises warning type WARN_TYPE for 
  7653. -   function my_func() */
  7654. -#define warning(err_num,fn_name) ev_err(__FILE__,err_num,__LINE__,fn_name,1) 
  7655. -
  7656. -
  7657. -/* error flags */
  7658. -#define    EF_EXIT        0    /* exit on error */
  7659. -#define    EF_ABORT    1    /* abort (dump core) on error */
  7660. -#define    EF_JUMP        2    /* jump on error */
  7661. -#define    EF_SILENT    3    /* jump, but don't print message */
  7662. -#define    ERREXIT()    set_err_flag(EF_EXIT)
  7663. -#define    ERRABORT()    set_err_flag(EF_ABORT)
  7664. -/* don't print message */
  7665. -#define    SILENTERR()    if ( ! setjmp(restart) ) set_err_flag(EF_SILENT)
  7666. -/* return here on error */
  7667. -#define    ON_ERROR()    if ( ! setjmp(restart) ) set_err_flag(EF_JUMP)
  7668. -
  7669. -
  7670. -/* error types */
  7671. -#define    E_UNKNOWN    0
  7672. -#define    E_SIZES        1
  7673. -#define    E_BOUNDS    2
  7674. -#define    E_MEM        3
  7675. -#define    E_SING        4
  7676. -#define    E_POSDEF    5
  7677. -#define    E_FORMAT    6
  7678. -#define    E_INPUT        7
  7679. -#define    E_NULL        8
  7680. -#define    E_SQUARE    9
  7681. -#define    E_RANGE        10
  7682. -#define    E_INSITU2    11
  7683. -#define    E_INSITU    12
  7684. -#define    E_ITER        13
  7685. -#define    E_CONV        14
  7686. -#define    E_START        15
  7687. -#define    E_SIGNAL    16
  7688. -#define    E_INTERN    17
  7689. -#define    E_EOF        18
  7690. -#define E_SHARED_VECS   19
  7691. -#define E_NEG           20
  7692. -#define E_OVERWRITE     21
  7693. -
  7694. -/* warning types */
  7695. -#define WARN_UNKNOWN         0
  7696. -#define WARN_WRONG_TYPE     1
  7697. -#define WARN_NO_MARK        2
  7698. -#define WARN_RES_LESS_0         3
  7699. -#define WARN_SHARED_VEC        4
  7700. -
  7701. -
  7702. -/* error catching macros */
  7703. -
  7704. -/* execute err_part if error errnum is raised while executing ok_part */
  7705. -#define    catch(errnum,ok_part,err_part)    \
  7706. -    {    jmp_buf _save;    int _err_num, _old_flag; \
  7707. -        _old_flag = set_err_flag(EF_SILENT); \
  7708. -        MEM_COPY(restart,_save,sizeof(jmp_buf)); \
  7709. -        if ( (_err_num=setjmp(restart)) == 0 ) \
  7710. -        {    ok_part; \
  7711. -            set_err_flag(_old_flag); \
  7712. -            MEM_COPY(_save,restart,sizeof(jmp_buf));    } \
  7713. -        else if ( _err_num == errnum ) \
  7714. -        {    set_err_flag(_old_flag);  \
  7715. -            MEM_COPY(_save,restart,sizeof(jmp_buf)); \
  7716. -            err_part;    } \
  7717. -        else {    set_err_flag(_old_flag); \
  7718. -            MEM_COPY(_save,restart,sizeof(jmp_buf)); \
  7719. -            error(_err_num,"catch"); \
  7720. -        } \
  7721. -    }
  7722. -
  7723. -
  7724. -/* execute err_part if any error raised while executing ok_part */
  7725. -#define    catchall(ok_part,err_part) \
  7726. -    {    jmp_buf _save;    int _err_num, _old_flag; \
  7727. -        _old_flag = set_err_flag(EF_SILENT); \
  7728. -        MEM_COPY(restart,_save,sizeof(jmp_buf)); \
  7729. -        if ( (_err_num=setjmp(restart)) == 0 ) \
  7730. -        {    ok_part; \
  7731. -            set_err_flag(_old_flag); \
  7732. -            MEM_COPY(_save,restart,sizeof(jmp_buf));    } \
  7733. -        else \
  7734. -        {    set_err_flag(_old_flag);  \
  7735. -            MEM_COPY(_save,restart,sizeof(jmp_buf)); \
  7736. -            err_part;    } \
  7737. -    }
  7738. -
  7739. -
  7740. -/* print message if error raised while executing ok_part,
  7741. -                then re-raise error to trace calls */
  7742. -#define    tracecatch(ok_part,function) \
  7743. -    {    jmp_buf _save;    int _err_num, _old_flag; \
  7744. -        _old_flag = set_err_flag(EF_JUMP); \
  7745. -        MEM_COPY(restart,_save,sizeof(jmp_buf)); \
  7746. -        if ( (_err_num=setjmp(restart)) == 0 ) \
  7747. -        {    ok_part; \
  7748. -            set_err_flag(_old_flag); \
  7749. -            MEM_COPY(_save,restart,sizeof(jmp_buf));    } \
  7750. -        else \
  7751. -        {    set_err_flag(_old_flag);  \
  7752. -            MEM_COPY(_save,restart,sizeof(jmp_buf)); \
  7753. -            error(_err_num,function);    } \
  7754. -    }
  7755. -
  7756. -
  7757. -
  7758. -#endif   /* ERRHEADER */
  7759. //GO.SYSIN DD err.h
  7760. echo meminfo.h 1>&2
  7761. sed >meminfo.h <<'//GO.SYSIN DD meminfo.h' 's/^-//'
  7762. -
  7763. -/**************************************************************************
  7764. -**
  7765. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  7766. -**
  7767. -**                 Meschach Library
  7768. -** 
  7769. -** This Meschach Library is provided "as is" without any express 
  7770. -** or implied warranty of any kind with respect to this software. 
  7771. -** In particular the authors shall not be liable for any direct, 
  7772. -** indirect, special, incidental or consequential damages arising 
  7773. -** in any way from use of the software.
  7774. -** 
  7775. -** Everyone is granted permission to copy, modify and redistribute this
  7776. -** Meschach Library, provided:
  7777. -**  1.  All copies contain this copyright notice.
  7778. -**  2.  All modified copies shall carry a notice stating who
  7779. -**      made the last modification and the date of such modification.
  7780. -**  3.  No charge is made for this software or works derived from it.  
  7781. -**      This clause shall not be construed as constraining other software
  7782. -**      distributed on the same medium as this software, nor is a
  7783. -**      distribution fee considered a charge.
  7784. -**
  7785. -***************************************************************************/
  7786. -
  7787. -
  7788. -/* meminfo.h  26/08/93 */
  7789. -/* changed  11/12/93 */
  7790. -
  7791. -
  7792. -#ifndef MEM_INFOH
  7793. -#define MEM_INFOH
  7794. -
  7795. -
  7796. -
  7797. -/* for hash table in mem_stat.c */
  7798. -/* Note: the hash size should be a prime, or at very least odd */
  7799. -#define MEM_HASHSIZE         509
  7800. -#define MEM_HASHSIZE_FILE    "meminfo.h"
  7801. -
  7802. -
  7803. -/* default: memory information is off */
  7804. -/* set it to 1 if you want it all the time */
  7805. -#define MEM_SWITCH_ON_DEF    0
  7806. -
  7807. -
  7808. -/* available standard types */
  7809. -#define TYPE_NULL              (-1)
  7810. -#define TYPE_MAT                0
  7811. -#define TYPE_BAND               1
  7812. -#define TYPE_PERM        2
  7813. -#define TYPE_VEC        3
  7814. -#define TYPE_IVEC        4
  7815. -
  7816. -#ifdef SPARSE
  7817. -#define TYPE_ITER        5
  7818. -#define TYPE_SPROW              6
  7819. -#define TYPE_SPMAT        7
  7820. -#endif
  7821. -
  7822. -#ifdef COMPLEX
  7823. -#ifdef SPARSE
  7824. -#define TYPE_ZVEC        8
  7825. -#define TYPE_ZMAT        9
  7826. -#else
  7827. -#define TYPE_ZVEC        5
  7828. -#define TYPE_ZMAT        6
  7829. -#endif
  7830. -#endif
  7831. -
  7832. -/* structure for memory information */
  7833. -typedef struct {
  7834. -   long bytes;       /* # of allocated bytes for each type (summary) */
  7835. -   int  numvar;      /* # of allocated variables for each type */
  7836. -} MEM_ARRAY;
  7837. -
  7838. -
  7839. -
  7840. -#ifdef ANSI_C
  7841. -
  7842. -int  mem_info_is_on(void);
  7843. -int mem_info_on(int sw);
  7844. -
  7845. -long mem_info_bytes(int type,int list);
  7846. -int mem_info_numvar(int type,int list);
  7847. -void mem_info_file(FILE * fp,int list);
  7848. -
  7849. -void mem_bytes_list(int type,int old_size,int new_size,
  7850. -               int list);
  7851. -void mem_numvar_list(int type, int num, int list);
  7852. -
  7853. -int mem_stat_reg_list(void **var,int type,int list);
  7854. -int mem_stat_mark(int mark);
  7855. -int mem_stat_free_list(int mark,int list);
  7856. -int mem_stat_show_mark(void);
  7857. -void mem_stat_dump(FILE *fp,int list);
  7858. -int mem_attach_list(int list,int ntypes,char *type_names[],
  7859. -    int (*free_funcs[])(), MEM_ARRAY info_sum[]);
  7860. -int mem_free_vars(int list);
  7861. -int mem_is_list_attached(int list);
  7862. -void mem_dump_list(FILE *fp,int list);
  7863. -int mem_stat_reg_vars(int list,int type,...);
  7864. -
  7865. -#else
  7866. -int mem_info_is_on();
  7867. -int mem_info_on();
  7868. -
  7869. -long mem_info_bytes();
  7870. -int mem_info_numvar();
  7871. -void mem_info_file();
  7872. -
  7873. -void mem_bytes_list();
  7874. -void mem_numvar_list();
  7875. -
  7876. -int mem_stat_reg_list();
  7877. -int mem_stat_mark();
  7878. -int mem_stat_free_list();
  7879. -int mem_stat_show_mark();
  7880. -void mem_stat_dump();
  7881. -int mem_attach_list();
  7882. -int mem_free_vars();
  7883. -int mem_is_list_attached();
  7884. -void mem_dump_list();
  7885. -int mem_stat_reg_vars();
  7886. -
  7887. -#endif 
  7888. -
  7889. -/* macros */
  7890. -
  7891. -#define mem_info()   mem_info_file(stdout,0)
  7892. -
  7893. -#define mem_stat_reg(var,type)  mem_stat_reg_list((void **)var,type,0)
  7894. -#define MEM_STAT_REG(var,type)  mem_stat_reg_list((void **)&(var),type,0)
  7895. -#define mem_stat_free(mark)   mem_stat_free_list(mark,0)
  7896. -
  7897. -#define mem_bytes(type,old_size,new_size)  \
  7898. -  mem_bytes_list(type,old_size,new_size,0)
  7899. -
  7900. -#define mem_numvar(type,num) mem_numvar_list(type,num,0)
  7901. -
  7902. -
  7903. -/* internal type */
  7904. -
  7905. -typedef struct {
  7906. -   char **type_names;        /* array of names of types (strings) */
  7907. -   int  (**free_funcs)();    /* array of functions for releasing types */
  7908. -   unsigned ntypes;          /* max number of types */
  7909. -   MEM_ARRAY *info_sum;      /* local array for keeping track of memory */
  7910. -} MEM_CONNECT;
  7911. -
  7912. -/* max number of lists of types */
  7913. -#define MEM_CONNECT_MAX_LISTS    5
  7914. -
  7915. -
  7916. -#endif
  7917. //GO.SYSIN DD meminfo.h
  7918. echo machine.h 1>&2
  7919. sed >machine.h <<'//GO.SYSIN DD machine.h' 's/^-//'
  7920. -/* machine.h.  Generated automatically by configure.  */
  7921. -/* Any machine specific stuff goes here */
  7922. -/* Add details necessary for your own installation here! */
  7923. -
  7924. -/* RCS id: $Id: $ */
  7925. -
  7926. -/* This is for use with "configure" -- if you are not using configure
  7927. -    then use machine.van for the "vanilla" version of machine.h */
  7928. -
  7929. -/* Note special macros: ANSI_C (ANSI C syntax)
  7930. -            SEGMENTED (segmented memory machine e.g. MS-DOS)
  7931. -            MALLOCDECL (declared if malloc() etc have
  7932. -                    been declared) */
  7933. -
  7934. -#define const 
  7935. -
  7936. -/* #undef MALLOCDECL */
  7937. -#define NOT_SEGMENTED 1
  7938. -#define HAVE_MEMORY_H 1
  7939. -/* #undef HAVE_COMPLEX_H */
  7940. -#define HAVE_MALLOC_H 1
  7941. -#define STDC_HEADERS 1
  7942. -#define HAVE_BCOPY 1
  7943. -#define HAVE_BZERO 1
  7944. -#define CHAR0ISDBL0 1
  7945. -#define WORDS_BIGENDIAN 1
  7946. -#define U_INT_DEF 1
  7947. -#define VARARGS 1
  7948. -#define HAVE_PROTOTYPES 1
  7949. -/* #undef HAVE_PROTOTYPES_IN_STRUCT */
  7950. -
  7951. -/* for inclusion into C++ files */
  7952. -#ifdef __cplusplus
  7953. -#define ANSI_C 1
  7954. -#ifndef HAVE_PROTOTYPES 
  7955. -#define HAVE_PROTOTYPES 1
  7956. -#endif
  7957. -#ifndef HAVE_PROTOTYPES_IN_STRUCT
  7958. -#define HAVE_PROTOTYPES_IN_STRUCT 1
  7959. -#endif
  7960. -#endif /* __cplusplus */
  7961. -
  7962. -/* example usage: VEC *PROTO(v_get,(int dim)); */
  7963. -#ifdef HAVE_PROTOTYPES
  7964. -#define    PROTO(name,args)    name args
  7965. -#else
  7966. -#define PROTO(name,args)    name()
  7967. -#endif /* HAVE_PROTOTYPES */
  7968. -#ifdef HAVE_PROTOTYPES_IN_STRUCT
  7969. -/* PROTO_() is to be used instead of PROTO() in struct's and typedef's */
  7970. -#define    PROTO_(name,args)    name args
  7971. -#else
  7972. -#define PROTO_(name,args)    name()
  7973. -#endif /* HAVE_PROTOTYPES_IN_STRUCT */
  7974. -
  7975. -/* for basic or larger versions */
  7976. -#define COMPLEX 1
  7977. -#define SPARSE 1
  7978. -
  7979. -/* for loop unrolling */
  7980. -/* #undef VUNROLL */
  7981. -/* #undef MUNROLL */
  7982. -
  7983. -/* for segmented memory */
  7984. -#ifndef NOT_SEGMENTED
  7985. -#define    SEGMENTED
  7986. -#endif
  7987. -
  7988. -/* if the system has malloc.h */
  7989. -#ifdef HAVE_MALLOC_H
  7990. -#define    MALLOCDECL    1
  7991. -#include    <malloc.h>
  7992. -#endif
  7993. -
  7994. -/* any compiler should have this header */
  7995. -/* if not, change it */
  7996. -#include        <stdio.h>
  7997. -
  7998. -
  7999. -/* Check for ANSI C memmove and memset */
  8000. -#ifdef STDC_HEADERS
  8001. -
  8002. -/* standard copy & zero functions */
  8003. -#define    MEM_COPY(from,to,size)    memmove((to),(from),(size))
  8004. -#define    MEM_ZERO(where,size)    memset((where),'\0',(size))
  8005. -
  8006. -#ifndef ANSI_C
  8007. -#define ANSI_C 1
  8008. -#endif
  8009. -
  8010. -#endif
  8011. -
  8012. -/* standard headers */
  8013. -#ifdef ANSI_C
  8014. -#include    <stdlib.h>
  8015. -#include    <stddef.h>
  8016. -#include    <string.h>
  8017. -#include    <float.h>
  8018. -#endif
  8019. -
  8020. -
  8021. -/* if have bcopy & bzero and no alternatives yet known, use them */
  8022. -#ifdef HAVE_BCOPY
  8023. -#ifndef MEM_COPY
  8024. -/* nonstandard copy function */
  8025. -#define    MEM_COPY(from,to,size)    bcopy((char *)(from),(char *)(to),(int)(size))
  8026. -#endif
  8027. -#endif
  8028. -
  8029. -#ifdef HAVE_BZERO
  8030. -#ifndef MEM_ZERO
  8031. -/* nonstandard zero function */
  8032. -#define    MEM_ZERO(where,size)    bzero((char *)(where),(int)(size))
  8033. -#endif
  8034. -#endif
  8035. -
  8036. -/* if the system has complex.h */
  8037. -#ifdef HAVE_COMPLEX_H
  8038. -#include    <complex.h>
  8039. -#endif
  8040. -
  8041. -/* If prototypes are available & ANSI_C not yet defined, then define it,
  8042. -    but don't include any header files as the proper ANSI C headers
  8043. -        aren't here */
  8044. -#ifdef HAVE_PROTOTYPES
  8045. -#ifndef ANSI_C
  8046. -#define ANSI_C  1
  8047. -#endif
  8048. -#endif
  8049. -
  8050. -/* floating point precision */
  8051. -
  8052. -/* you can choose single, double or long double (if available) precision */
  8053. -
  8054. -#define FLOAT         1
  8055. -#define DOUBLE         2
  8056. -#define LONG_DOUBLE     3
  8057. -
  8058. -/* #undef REAL_FLT */
  8059. -/* #undef REAL_DBL */
  8060. -
  8061. -/* if nothing is defined, choose double precision */
  8062. -#ifndef REAL_DBL
  8063. -#ifndef REAL_FLT
  8064. -#define REAL_DBL 1
  8065. -#endif
  8066. -#endif
  8067. -
  8068. -/* single precision */
  8069. -#ifdef REAL_FLT
  8070. -#define  Real float
  8071. -#define  LongReal float
  8072. -#define REAL FLOAT
  8073. -#define LONGREAL FLOAT
  8074. -#endif
  8075. -
  8076. -/* double precision */
  8077. -#ifdef REAL_DBL
  8078. -#define Real double
  8079. -#define LongReal double
  8080. -#define REAL DOUBLE
  8081. -#define LONGREAL DOUBLE
  8082. -#endif
  8083. -
  8084. -
  8085. -/* machine epsilon or unit roundoff error */
  8086. -/* This is correct on most IEEE Real precision systems */
  8087. -#ifdef DBL_EPSILON
  8088. -#if REAL == DOUBLE
  8089. -#define    MACHEPS    DBL_EPSILON
  8090. -#elif REAL == FLOAT
  8091. -#define    MACHEPS    FLT_EPSILON
  8092. -#elif REAL == LONGDOUBLE
  8093. -#define MACHEPS LDBL_EPSILON
  8094. -#endif
  8095. -#endif
  8096. -
  8097. -#define F_MACHEPS 1.19209e-07
  8098. -#define D_MACHEPS 2.22045e-16
  8099. -
  8100. -#ifndef MACHEPS
  8101. -#if REAL == DOUBLE
  8102. -#define    MACHEPS    D_MACHEPS
  8103. -#elif REAL == FLOAT  
  8104. -#define MACHEPS F_MACHEPS
  8105. -#elif REAL == LONGDOUBLE
  8106. -#define MACHEPS D_MACHEPS
  8107. -#endif
  8108. -#endif
  8109. -
  8110. -/* #undef M_MACHEPS */
  8111. -
  8112. -/********************
  8113. -#ifdef DBL_EPSILON
  8114. -#define    MACHEPS    DBL_EPSILON
  8115. -#endif
  8116. -#ifdef M_MACHEPS
  8117. -#ifndef MACHEPS
  8118. -#define MACHEPS    M_MACHEPS
  8119. -#endif
  8120. -#endif
  8121. -********************/
  8122. -
  8123. -#define    M_MAX_INT 2147483647
  8124. -#ifdef    M_MAX_INT
  8125. -#ifndef MAX_RAND
  8126. -#define    MAX_RAND ((double)(M_MAX_INT))
  8127. -#endif
  8128. -#endif
  8129. -
  8130. -/* for non-ANSI systems */
  8131. -#ifndef HUGE_VAL
  8132. -#define HUGE_VAL HUGE
  8133. -#endif
  8134. -
  8135. -
  8136. -#ifdef ANSI_C
  8137. -extern    int    isatty(int);
  8138. -#endif
  8139. -
  8140. //GO.SYSIN DD machine.h
  8141. echo matrix.h 1>&2
  8142. sed >matrix.h <<'//GO.SYSIN DD matrix.h' 's/^-//'
  8143. -
  8144. -/**************************************************************************
  8145. -**
  8146. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  8147. -**
  8148. -**                 Meschach Library
  8149. -** 
  8150. -** This Meschach Library is provided "as is" without any express 
  8151. -** or implied warranty of any kind with respect to this software. 
  8152. -** In particular the authors shall not be liable for any direct, 
  8153. -** indirect, special, incidental or consequential damages arising 
  8154. -** in any way from use of the software.
  8155. -** 
  8156. -** Everyone is granted permission to copy, modify and redistribute this
  8157. -** Meschach Library, provided:
  8158. -**  1.  All copies contain this copyright notice.
  8159. -**  2.  All modified copies shall carry a notice stating who
  8160. -**      made the last modification and the date of such modification.
  8161. -**  3.  No charge is made for this software or works derived from it.  
  8162. -**      This clause shall not be construed as constraining other software
  8163. -**      distributed on the same medium as this software, nor is a
  8164. -**      distribution fee considered a charge.
  8165. -**
  8166. -***************************************************************************/
  8167. -
  8168. -
  8169. -/*
  8170. -        Type definitions for general purpose maths package
  8171. -*/
  8172. -
  8173. -#ifndef    MATRIXH
  8174. -
  8175. -/* RCS id: $Id: matrix.h,v 1.18 1994/04/16 00:33:37 des Exp $ */
  8176. -
  8177. -#define    MATRIXH    
  8178. -
  8179. -#include    "machine.h"
  8180. -#include        "err.h"
  8181. -#include     "meminfo.h"
  8182. -
  8183. -/* unsigned integer type */
  8184. -#ifndef U_INT_DEF
  8185. -typedef    unsigned int    u_int;
  8186. -#define U_INT_DEF
  8187. -#endif
  8188. -
  8189. -/* vector definition */
  8190. -typedef    struct    {
  8191. -        u_int    dim, max_dim;
  8192. -        Real    *ve;
  8193. -        } VEC;
  8194. -
  8195. -/* matrix definition */
  8196. -typedef    struct    {
  8197. -        u_int    m, n;
  8198. -        u_int    max_m, max_n, max_size;
  8199. -        Real    **me,*base;    /* base is base of alloc'd mem */
  8200. -        } MAT;
  8201. -
  8202. -/* band matrix definition */
  8203. -typedef struct {
  8204. -               MAT   *mat;       /* matrix */
  8205. -               int   lb,ub;    /* lower and upper bandwidth */
  8206. -               } BAND;
  8207. -
  8208. -
  8209. -/* permutation definition */
  8210. -typedef    struct    {
  8211. -        u_int    size, max_size, *pe;
  8212. -        } PERM;
  8213. -
  8214. -/* integer vector definition */
  8215. -typedef struct    {
  8216. -        u_int    dim, max_dim;
  8217. -        int    *ive;
  8218. -            } IVEC;
  8219. -
  8220. -
  8221. -#ifndef MALLOCDECL
  8222. -#ifndef ANSI_C
  8223. -extern    char    *malloc(), *calloc(), *realloc();
  8224. -#else
  8225. -extern    void    *malloc(size_t),
  8226. -        *calloc(size_t,size_t),
  8227. -        *realloc(void *,size_t);
  8228. -#endif
  8229. -#endif
  8230. -
  8231. -#ifndef ANSI_C
  8232. -extern void m_version();
  8233. -#else
  8234. -void    m_version( void );
  8235. -#endif
  8236. -
  8237. -#ifndef ANSI_C
  8238. -/* allocate one object of given type */
  8239. -#define    NEW(type)    ((type *)calloc(1,sizeof(type)))
  8240. -
  8241. -/* allocate num objects of given type */
  8242. -#define    NEW_A(num,type)    ((type *)calloc((unsigned)(num),sizeof(type)))
  8243. -
  8244. - /* re-allocate arry to have num objects of the given type */
  8245. -#define    RENEW(var,num,type) \
  8246. -    ((var)=(type *)((var) ? \
  8247. -            realloc((char *)(var),(unsigned)(num)*sizeof(type)) : \
  8248. -            calloc((unsigned)(num),sizeof(type))))
  8249. -
  8250. -#define    MEMCOPY(from,to,n_items,type) \
  8251. -    MEM_COPY((char *)(from),(char *)(to),(unsigned)(n_items)*sizeof(type))
  8252. -
  8253. -#else
  8254. -/* allocate one object of given type */
  8255. -#define    NEW(type)    ((type *)calloc((size_t)1,(size_t)sizeof(type)))
  8256. -
  8257. -/* allocate num objects of given type */
  8258. -#define    NEW_A(num,type)    ((type *)calloc((size_t)(num),(size_t)sizeof(type)))
  8259. -
  8260. - /* re-allocate arry to have num objects of the given type */
  8261. -#define    RENEW(var,num,type) \
  8262. -    ((var)=(type *)((var) ? \
  8263. -            realloc((char *)(var),(size_t)((num)*sizeof(type))) : \
  8264. -            calloc((size_t)(num),(size_t)sizeof(type))))
  8265. -
  8266. -#define    MEMCOPY(from,to,n_items,type) \
  8267. - MEM_COPY((char *)(from),(char *)(to),(unsigned)(n_items)*sizeof(type))
  8268. -
  8269. -#endif
  8270. -
  8271. -/* type independent min and max operations */
  8272. -#ifndef max
  8273. -#define    max(a,b)    ((a) > (b) ? (a) : (b))
  8274. -#endif
  8275. -#ifndef min
  8276. -#define    min(a,b)    ((a) > (b) ? (b) : (a))
  8277. -#endif
  8278. -
  8279. -
  8280. -#undef TRUE
  8281. -#define    TRUE    1
  8282. -#undef FALSE
  8283. -#define    FALSE    0
  8284. -
  8285. -
  8286. -/* for input routines */
  8287. -#define MAXLINE 81
  8288. -
  8289. -
  8290. -/* Dynamic memory allocation */
  8291. -
  8292. -/* Should use M_FREE/V_FREE/PX_FREE in programs instead of m/v/px_free()
  8293. -   as this is considerably safer -- also provides a simple type check ! */
  8294. -
  8295. -#ifndef ANSI_C
  8296. -
  8297. -extern    VEC *v_get(), *v_resize();
  8298. -extern    MAT *m_get(), *m_resize();
  8299. -extern    PERM *px_get(), *px_resize();
  8300. -extern    IVEC *iv_get(), *iv_resize();
  8301. -extern    int m_free(),v_free();
  8302. -extern  int px_free();
  8303. -extern  int iv_free();
  8304. -extern  BAND *bd_get(), *bd_resize();
  8305. -extern  int bd_free();
  8306. -
  8307. -#else
  8308. -
  8309. -/* get/resize vector to given dimension */
  8310. -extern    VEC *v_get(int), *v_resize(VEC *,int);
  8311. -/* get/resize matrix to be m x n */
  8312. -extern    MAT *m_get(int,int), *m_resize(MAT *,int,int);
  8313. -/* get/resize permutation to have the given size */
  8314. -extern    PERM *px_get(int), *px_resize(PERM *,int);
  8315. -/* get/resize an integer vector to given dimension */
  8316. -extern    IVEC *iv_get(int), *iv_resize(IVEC *,int);
  8317. -/* get/resize a band matrix to given dimension */
  8318. -extern  BAND *bd_get(int,int,int), *bd_resize(BAND *,int,int,int);
  8319. -
  8320. -/* free (de-allocate) (band) matrices, vectors, permutations and 
  8321. -   integer vectors */
  8322. -extern  int iv_free(IVEC *);
  8323. -extern    m_free(MAT *),v_free(VEC *),px_free(PERM *);
  8324. -extern   int bd_free(BAND *);
  8325. -
  8326. -#endif
  8327. -
  8328. -
  8329. -/* MACROS */
  8330. -
  8331. -/* macros that also check types and sets pointers to NULL */
  8332. -#define    M_FREE(mat)    ( m_free(mat),    (mat)=(MAT *)NULL )
  8333. -#define V_FREE(vec)    ( v_free(vec),    (vec)=(VEC *)NULL )
  8334. -#define    PX_FREE(px)    ( px_free(px),    (px)=(PERM *)NULL )
  8335. -#define    IV_FREE(iv)    ( iv_free(iv),    (iv)=(IVEC *)NULL )
  8336. -
  8337. -#define MAXDIM      2001
  8338. -
  8339. -
  8340. -/* Entry level access to data structures */
  8341. -#ifdef DEBUG
  8342. -
  8343. -/* returns x[i] */
  8344. -#define    v_entry(x,i)    (((i) < 0 || (i) >= (x)->dim) ? \
  8345. -             error(E_BOUNDS,"v_entry"), 0.0 : (x)->ve[i] )
  8346. -
  8347. -/* x[i] <- val */
  8348. -#define    v_set_val(x,i,val) ((x)->ve[i] = ((i) < 0 || (i) >= (x)->dim) ? \
  8349. -                error(E_BOUNDS,"v_set_val"), 0.0 : (val))
  8350. -
  8351. -/* x[i] <- x[i] + val */
  8352. -#define    v_add_val(x,i,val) ((x)->ve[i] += ((i) < 0 || (i) >= (x)->dim) ? \
  8353. -                error(E_BOUNDS,"v_add_val"), 0.0 : (val))
  8354. -
  8355. -/* x[i] <- x[i] - val */
  8356. -#define    v_sub_val(x,i,val) ((x)->ve[i] -= ((i) < 0 || (i) >= (x)->dim) ? \
  8357. -                error(E_BOUNDS,"v_sub_val"), 0.0 : (val))
  8358. -
  8359. -/* returns A[i][j] */
  8360. -#define    m_entry(A,i,j)    (((i) < 0 || (i) >= (A)->m || \
  8361. -              (j) < 0 || (j) >= (A)->n) ? \
  8362. -             error(E_BOUNDS,"m_entry"), 0.0 : (A)->me[i][j] )
  8363. -
  8364. -/* A[i][j] <- val */
  8365. -#define    m_set_val(A,i,j,val) ((A)->me[i][j] = ((i) < 0 || (i) >= (A)->m || \
  8366. -                           (j) < 0 || (j) >= (A)->n) ? \
  8367. -                  error(E_BOUNDS,"m_set_val"), 0.0 : (val) )
  8368. -
  8369. -/* A[i][j] <- A[i][j] + val */
  8370. -#define    m_add_val(A,i,j,val) ((A)->me[i][j] += ((i) < 0 || (i) >= (A)->m || \
  8371. -                        (j) < 0 || (j) >= (A)->n) ? \
  8372. -                  error(E_BOUNDS,"m_add_val"), 0.0 : (val) )
  8373. -
  8374. -/* A[i][j] <- A[i][j] - val */
  8375. -#define    m_sub_val(A,i,j,val) ((A)->me[i][j] -= ((i) < 0 || (i) >= (A)->m || \
  8376. -                        (j) < 0 || (j) >= (A)->n) ? \
  8377. -                  error(E_BOUNDS,"m_sub_val"), 0.0 : (val) )
  8378. -#else
  8379. -
  8380. -/* returns x[i] */
  8381. -#define    v_entry(x,i)        ((x)->ve[i])
  8382. -
  8383. -/* x[i] <- val */
  8384. -#define    v_set_val(x,i,val)    ((x)->ve[i]  = (val))
  8385. -
  8386. -/* x[i] <- x[i] + val */
  8387. -#define    v_add_val(x,i,val)    ((x)->ve[i] += (val))
  8388. -
  8389. - /* x[i] <- x[i] - val */
  8390. -#define    v_sub_val(x,i,val)    ((x)->ve[i] -= (val))
  8391. -
  8392. -/* returns A[i][j] */
  8393. -#define    m_entry(A,i,j)        ((A)->me[i][j])
  8394. -
  8395. -/* A[i][j] <- val */
  8396. -#define    m_set_val(A,i,j,val)    ((A)->me[i][j]  = (val) )
  8397. -
  8398. -/* A[i][j] <- A[i][j] + val */
  8399. -#define    m_add_val(A,i,j,val)    ((A)->me[i][j] += (val) )
  8400. -
  8401. -/* A[i][j] <- A[i][j] - val */
  8402. -#define    m_sub_val(A,i,j,val)    ((A)->me[i][j] -= (val) )
  8403. -
  8404. -#endif
  8405. -
  8406. -
  8407. -/* I/O routines */
  8408. -#ifndef ANSI_C
  8409. -
  8410. -extern    void v_foutput(),m_foutput(),px_foutput();
  8411. -extern  void iv_foutput();
  8412. -extern    VEC *v_finput();
  8413. -extern    MAT *m_finput();
  8414. -extern    PERM *px_finput();
  8415. -extern    IVEC *iv_finput();
  8416. -extern    int fy_or_n(), fin_int(), yn_dflt(), skipjunk();
  8417. -extern    double fin_double();
  8418. -
  8419. -#else
  8420. -
  8421. -/* print x on file fp */
  8422. -void v_foutput(FILE *fp,VEC *x),
  8423. -       /* print A on file fp */
  8424. -    m_foutput(FILE *fp,MAT *A),
  8425. -       /* print px on file fp */
  8426. -    px_foutput(FILE *fp,PERM *px);
  8427. -/* print ix on file fp */
  8428. -void iv_foutput(FILE *fp,IVEC *ix);
  8429. -
  8430. -/* Note: if out is NULL, then returned object is newly allocated;
  8431. -        Also: if out is not NULL, then that size is assumed */
  8432. -
  8433. -/* read in vector from fp */
  8434. -VEC *v_finput(FILE *fp,VEC *out);
  8435. -/* read in matrix from fp */
  8436. -MAT *m_finput(FILE *fp,MAT *out);
  8437. -/* read in permutation from fp */
  8438. -PERM *px_finput(FILE *fp,PERM *out);
  8439. -/* read in int vector from fp */
  8440. -IVEC *iv_finput(FILE *fp,IVEC *out);
  8441. -
  8442. -/* fy_or_n -- yes-or-no to question in string s
  8443. -        -- question written to stderr, input from fp 
  8444. -        -- if fp is NOT a tty then return y_n_dflt */
  8445. -int fy_or_n(FILE *fp,char *s);
  8446. -
  8447. -/* yn_dflt -- sets the value of y_n_dflt to val */
  8448. -int yn_dflt(int val);
  8449. -
  8450. -/* fin_int -- return integer read from file/stream fp
  8451. -        -- prompt s on stderr if fp is a tty
  8452. -        -- check that x lies between low and high: re-prompt if
  8453. -                fp is a tty, error exit otherwise
  8454. -        -- ignore check if low > high           */
  8455. -int fin_int(FILE *fp,char *s,int low,int high);
  8456. -
  8457. -/* fin_double -- return double read from file/stream fp
  8458. -        -- prompt s on stderr if fp is a tty
  8459. -        -- check that x lies between low and high: re-prompt if
  8460. -                fp is a tty, error exit otherwise
  8461. -        -- ignore check if low > high           */
  8462. -double fin_double(FILE *fp,char *s,double low,double high);
  8463. -
  8464. -/* it skips white spaces and strings of the form #....\n
  8465. -   Here .... is a comment string */
  8466. -int skipjunk(FILE *fp);
  8467. -
  8468. -#endif
  8469. -
  8470. -
  8471. -/* MACROS */
  8472. -
  8473. -/* macros to use stdout and stdin instead of explicit fp */
  8474. -#define    v_output(vec)    v_foutput(stdout,vec)
  8475. -#define    v_input(vec)    v_finput(stdin,vec)
  8476. -#define    m_output(mat)    m_foutput(stdout,mat)
  8477. -#define    m_input(mat)    m_finput(stdin,mat)
  8478. -#define    px_output(px)    px_foutput(stdout,px)
  8479. -#define    px_input(px)    px_finput(stdin,px)
  8480. -#define    iv_output(iv)    iv_foutput(stdout,iv)
  8481. -#define    iv_input(iv)    iv_finput(stdin,iv)
  8482. -
  8483. -/* general purpose input routine; skips comments # ... \n */
  8484. -#define    finput(fp,prompt,fmt,var) \
  8485. -    ( ( isatty(fileno(fp)) ? fprintf(stderr,prompt) : skipjunk(fp) ), \
  8486. -                            fscanf(fp,fmt,var) )
  8487. -#define    input(prompt,fmt,var)    finput(stdin,prompt,fmt,var)
  8488. -#define    fprompter(fp,prompt) \
  8489. -    ( isatty(fileno(fp)) ? fprintf(stderr,prompt) : skipjunk(fp) )
  8490. -#define    prompter(prompt)    fprompter(stdin,prompt)
  8491. -#define    y_or_n(s)    fy_or_n(stdin,s)
  8492. -#define    in_int(s,lo,hi)    fin_int(stdin,s,lo,hi)
  8493. -#define    in_double(s,lo,hi)    fin_double(stdin,s,lo,hi)
  8494. -
  8495. -/* Copying routines */
  8496. -#ifndef ANSI_C
  8497. -extern    MAT    *_m_copy(), *m_move(), *vm_move();
  8498. -extern    VEC    *_v_copy(), *v_move(), *mv_move();
  8499. -extern    PERM    *px_copy();
  8500. -extern    IVEC    *iv_copy(), *iv_move();
  8501. -extern  BAND    *bd_copy();
  8502. -
  8503. -#else
  8504. -
  8505. -/* copy in to out starting at out[i0][j0] */
  8506. -extern    MAT    *_m_copy(MAT *in,MAT *out,u_int i0,u_int j0),
  8507. -        * m_move(MAT *in, int, int, int, int, MAT *out, int, int),
  8508. -        *vm_move(VEC *in, int, MAT *out, int, int, int, int);
  8509. -/* copy in to out starting at out[i0] */
  8510. -extern    VEC    *_v_copy(VEC *in,VEC *out,u_int i0),
  8511. -        * v_move(VEC *in, int, int, VEC *out, int),
  8512. -        *mv_move(MAT *in, int, int, int, int, VEC *out, int);
  8513. -extern    PERM    *px_copy(PERM *in,PERM *out);
  8514. -extern    IVEC    *iv_copy(IVEC *in,IVEC *out),
  8515. -        *iv_move(IVEC *in, int, int, IVEC *out, int);
  8516. -extern  BAND    *bd_copy(BAND *in,BAND *out);
  8517. -
  8518. -#endif
  8519. -
  8520. -
  8521. -/* MACROS */
  8522. -#define    m_copy(in,out)    _m_copy(in,out,0,0)
  8523. -#define    v_copy(in,out)    _v_copy(in,out,0)
  8524. -
  8525. -
  8526. -/* Initialisation routines -- to be zero, ones, random or identity */
  8527. -#ifndef ANSI_C
  8528. -extern    VEC     *v_zero(), *v_rand(), *v_ones();
  8529. -extern    MAT     *m_zero(), *m_ident(), *m_rand(), *m_ones();
  8530. -extern    PERM    *px_ident();
  8531. -extern  IVEC    *iv_zero();
  8532. -#else
  8533. -extern    VEC     *v_zero(VEC *), *v_rand(VEC *), *v_ones(VEC *);
  8534. -extern    MAT     *m_zero(MAT *), *m_ident(MAT *), *m_rand(MAT *),
  8535. -                        *m_ones(MAT *);
  8536. -extern    PERM    *px_ident(PERM *);
  8537. -extern  IVEC    *iv_zero(IVEC *);
  8538. -#endif
  8539. -
  8540. -/* Basic vector operations */
  8541. -#ifndef ANSI_C
  8542. -extern    VEC *sv_mlt(), *mv_mlt(), *vm_mlt(), *v_add(), *v_sub(),
  8543. -        *px_vec(), *pxinv_vec(), *v_mltadd(), *v_map(), *_v_map(),
  8544. -        *v_lincomb(), *v_linlist();
  8545. -extern    double    v_min(), v_max(), v_sum();
  8546. -extern    VEC    *v_star(), *v_slash(), *v_sort();
  8547. -extern    double _in_prod(), __ip__();
  8548. -extern    void    __mltadd__(), __add__(), __sub__(), 
  8549. -                __smlt__(), __zero__();
  8550. -#else
  8551. -
  8552. -extern    VEC    *sv_mlt(double,VEC *,VEC *),    /* out <- s.x */
  8553. -        *mv_mlt(MAT *,VEC *,VEC *),    /* out <- A.x */
  8554. -        *vm_mlt(MAT *,VEC *,VEC *),    /* out^T <- x^T.A */
  8555. -        *v_add(VEC *,VEC *,VEC *),     /* out <- x + y */
  8556. -                *v_sub(VEC *,VEC *,VEC *),    /* out <- x - y */
  8557. -        *px_vec(PERM *,VEC *,VEC *),    /* out <- P.x */
  8558. -        *pxinv_vec(PERM *,VEC *,VEC *),      /* out <- P^{-1}.x */
  8559. -        *v_mltadd(VEC *,VEC *,double,VEC *),   /* out <- x + s.y */
  8560. -#ifdef PROTOTYPES_IN_STRUCT
  8561. -        *v_map(double (*f)(double),VEC *,VEC *),  
  8562. -                                                 /* out[i] <- f(x[i]) */
  8563. -        *_v_map(double (*f)(void *,double),void *,VEC *,VEC *),
  8564. -#else
  8565. -        *v_map(double (*f)(),VEC *,VEC *), /* out[i] <- f(x[i]) */
  8566. -        *_v_map(double (*f)(),void *,VEC *,VEC *),
  8567. -#endif
  8568. -        *v_lincomb(int,VEC **,Real *,VEC *),   
  8569. -                                                 /* out <- sum_i s[i].x[i] */
  8570. -                *v_linlist(VEC *out,VEC *v1,double a1,...);
  8571. -                                              /* out <- s1.x1 + s2.x2 + ... */
  8572. -
  8573. -/* returns min_j x[j] (== x[i]) */
  8574. -extern    double    v_min(VEC *, int *), 
  8575. -     /* returns max_j x[j] (== x[i]) */        
  8576. -        v_max(VEC *, int *), 
  8577. -        /* returns sum_i x[i] */
  8578. -        v_sum(VEC *);
  8579. -
  8580. -/* Hadamard product: out[i] <- x[i].y[i] */
  8581. -extern    VEC    *v_star(VEC *, VEC *, VEC *),
  8582. -                 /* out[i] <- x[i] / y[i] */
  8583. -        *v_slash(VEC *, VEC *, VEC *),
  8584. -               /* sorts x, and sets order so that sorted x[i] = x[order[i]] */ 
  8585. -        *v_sort(VEC *, PERM *);
  8586. -
  8587. -/* returns inner product starting at component i0 */
  8588. -extern    double    _in_prod(VEC *x,VEC *y,u_int i0), 
  8589. -                /* returns sum_{i=0}^{len-1} x[i].y[i] */
  8590. -                __ip__(Real *,Real *,int);
  8591. -
  8592. -/* see v_mltadd(), v_add(), v_sub() and v_zero() */
  8593. -extern    void    __mltadd__(Real *,Real *,double,int),
  8594. -        __add__(Real *,Real *,Real *,int),
  8595. -        __sub__(Real *,Real *,Real *,int),
  8596. -                __smlt__(Real *,double,Real *,int),
  8597. -        __zero__(Real *,int);
  8598. -
  8599. -#endif
  8600. -
  8601. -
  8602. -/* MACRO */
  8603. -/* usual way of computing the inner product */
  8604. -#define    in_prod(a,b)    _in_prod(a,b,0)
  8605. -
  8606. -/* Norms */
  8607. -/* scaled vector norms -- scale == NULL implies unscaled */
  8608. -#ifndef ANSI_C
  8609. -
  8610. -extern    double    _v_norm1(), _v_norm2(), _v_norm_inf(),
  8611. -        m_norm1(), m_norm_inf(), m_norm_frob();
  8612. -
  8613. -#else
  8614. -               /* returns sum_i |x[i]/scale[i]| */
  8615. -extern    double    _v_norm1(VEC *x,VEC *scale),   
  8616. -               /* returns (scaled) Euclidean norm */
  8617. -                _v_norm2(VEC *x,VEC *scale),
  8618. -               /* returns max_i |x[i]/scale[i]| */
  8619. -        _v_norm_inf(VEC *x,VEC *scale);
  8620. -
  8621. -/* unscaled matrix norms */
  8622. -extern double m_norm1(MAT *A), m_norm_inf(MAT *A), m_norm_frob(MAT *A);
  8623. -
  8624. -#endif
  8625. -
  8626. -
  8627. -/* MACROS */
  8628. -/* unscaled vector norms */
  8629. -#define    v_norm1(x)    _v_norm1(x,VNULL)
  8630. -#define    v_norm2(x)    _v_norm2(x,VNULL)
  8631. -#define    v_norm_inf(x)    _v_norm_inf(x,VNULL)
  8632. -
  8633. -/* Basic matrix operations */
  8634. -#ifndef ANSI_C
  8635. -
  8636. -extern    MAT *sm_mlt(), *m_mlt(), *mmtr_mlt(), *mtrm_mlt(), *m_add(), *m_sub(),
  8637. -        *sub_mat(), *m_transp(), *ms_mltadd();
  8638. -
  8639. -extern   BAND *bd_transp();
  8640. -extern    MAT *px_rows(), *px_cols(), *swap_rows(), *swap_cols(),
  8641. -             *_set_row(), *_set_col();
  8642. -extern    VEC *get_row(), *get_col(), *sub_vec(),
  8643. -        *mv_mltadd(), *vm_mltadd();
  8644. -
  8645. -#else
  8646. -
  8647. -extern    MAT    *sm_mlt(double s,MAT *A,MAT *out),     /* out <- s.A */
  8648. -        *m_mlt(MAT *A,MAT *B,MAT *out),    /* out <- A.B */
  8649. -        *mmtr_mlt(MAT *A,MAT *B,MAT *out),    /* out <- A.B^T */
  8650. -        *mtrm_mlt(MAT *A,MAT *B,MAT *out),    /* out <- A^T.B */
  8651. -        *m_add(MAT *A,MAT *B,MAT *out),    /* out <- A + B */
  8652. -        *m_sub(MAT *A,MAT *B,MAT *out),    /* out <- A - B */
  8653. -        *sub_mat(MAT *A,u_int,u_int,u_int,u_int,MAT *out),
  8654. -        *m_transp(MAT *A,MAT *out),        /* out <- A^T */
  8655. -                /* out <- A + s.B */ 
  8656. -        *ms_mltadd(MAT *A,MAT *B,double s,MAT *out);   
  8657. -
  8658. -
  8659. -extern  BAND    *bd_transp(BAND *in, BAND *out);   /* out <- A^T */
  8660. -extern    MAT    *px_rows(PERM *px,MAT *A,MAT *out),    /* out <- P.A */
  8661. -        *px_cols(PERM *px,MAT *A,MAT *out),    /* out <- A.P^T */
  8662. -        *swap_rows(MAT *,int,int,int,int),
  8663. -        *swap_cols(MAT *,int,int,int,int),
  8664. -                 /* A[i][j] <- out[j], j >= j0 */
  8665. -        *_set_col(MAT *A,u_int i,VEC *out,u_int j0),
  8666. -                 /* A[i][j] <- out[i], i >= i0 */
  8667. -        *_set_row(MAT *A,u_int j,VEC *out,u_int i0);
  8668. -
  8669. -extern    VEC    *get_row(MAT *,u_int,VEC *),
  8670. -        *get_col(MAT *,u_int,VEC *),
  8671. -        *sub_vec(VEC *,int,int,VEC *),
  8672. -                   /* out <- x + s.A.y */
  8673. -        *mv_mltadd(VEC *x,VEC *y,MAT *A,double s,VEC *out),
  8674. -                  /* out^T <- x^T + s.y^T.A */
  8675. -        *vm_mltadd(VEC *x,VEC *y,MAT *A,double s,VEC *out);
  8676. -#endif
  8677. -
  8678. -
  8679. -/* MACROS */
  8680. -/* row i of A <- vec */
  8681. -#define    set_row(mat,row,vec)    _set_row(mat,row,vec,0) 
  8682. -/* col j of A <- vec */
  8683. -#define    set_col(mat,col,vec)    _set_col(mat,col,vec,0)
  8684. -
  8685. -
  8686. -/* Basic permutation operations */
  8687. -#ifndef ANSI_C
  8688. -
  8689. -extern    PERM *px_mlt(), *px_inv(), *px_transp();
  8690. -extern    int  px_sign();
  8691. -
  8692. -#else
  8693. -
  8694. -extern    PERM    *px_mlt(PERM *px1,PERM *px2,PERM *out),    /* out <- px1.px2 */
  8695. -        *px_inv(PERM *px,PERM *out),    /* out <- px^{-1} */
  8696. -                 /* swap px[i] and px[j] */
  8697. -        *px_transp(PERM *px,u_int i,u_int j);
  8698. -
  8699. -     /* returns sign(px) = +1 if px product of even # transpositions
  8700. -                           -1 if ps product of odd  # transpositions */
  8701. -extern    int    px_sign(PERM *);
  8702. -
  8703. -#endif
  8704. -
  8705. -
  8706. -/* Basic integer vector operations */
  8707. -#ifndef ANSI_C
  8708. -
  8709. -extern    IVEC    *iv_add(), *iv_sub(), *iv_sort();
  8710. -
  8711. -#else
  8712. -
  8713. -extern    IVEC    *iv_add(IVEC *ix,IVEC *iy,IVEC *out),  /* out <- ix + iy */
  8714. -        *iv_sub(IVEC *ix,IVEC *iy,IVEC *out),  /* out <- ix - iy */
  8715. -        /* sorts ix & sets order so that sorted ix[i] = old ix[order[i]] */
  8716. -        *iv_sort(IVEC *ix, PERM *order);
  8717. -
  8718. -#endif
  8719. -
  8720. -
  8721. -/* miscellaneous functions */
  8722. -
  8723. -#ifndef ANSI_C
  8724. -
  8725. -extern    double    square(), cube(), mrand();
  8726. -extern    void    smrand(), mrandlist();
  8727. -extern  void    m_dump(), px_dump(), v_dump(), iv_dump();
  8728. -extern MAT *band2mat();
  8729. -extern BAND *mat2band();
  8730. -
  8731. -#else
  8732. -
  8733. -double    square(double x),     /* returns x^2 */
  8734. -  cube(double x),         /* returns x^3 */
  8735. -  mrand(void);                  /* returns random # in [0,1) */
  8736. -
  8737. -void    smrand(int seed),            /* seeds mrand() */
  8738. -  mrandlist(Real *x, int len);       /* generates len random numbers */
  8739. -
  8740. -void    m_dump(FILE *fp,MAT *a), px_dump(FILE *,PERM *px),
  8741. -        v_dump(FILE *fp,VEC *x), iv_dump(FILE *fp, IVEC *ix);
  8742. -
  8743. -MAT *band2mat(BAND *bA, MAT *A);
  8744. -BAND *mat2band(MAT *A, int lb,int ub, BAND *bA);
  8745. -
  8746. -#endif
  8747. -
  8748. -
  8749. -/* miscellaneous constants */
  8750. -#define    VNULL    ((VEC *)NULL)
  8751. -#define    MNULL    ((MAT *)NULL)
  8752. -#define    PNULL    ((PERM *)NULL)
  8753. -#define    IVNULL    ((IVEC *)NULL)
  8754. -#define BDNULL  ((BAND *)NULL)
  8755. -
  8756. -
  8757. -
  8758. -/* varying number of arguments */
  8759. -
  8760. -#ifdef ANSI_C
  8761. -#include <stdarg.h>
  8762. -
  8763. -/* prototypes */
  8764. -
  8765. -int v_get_vars(int dim,...);
  8766. -int iv_get_vars(int dim,...);
  8767. -int m_get_vars(int m,int n,...);
  8768. -int px_get_vars(int dim,...);
  8769. -
  8770. -int v_resize_vars(int new_dim,...);
  8771. -int iv_resize_vars(int new_dim,...);
  8772. -int m_resize_vars(int m,int n,...);
  8773. -int px_resize_vars(int new_dim,...);
  8774. -
  8775. -int v_free_vars(VEC **,...);
  8776. -int iv_free_vars(IVEC **,...);
  8777. -int px_free_vars(PERM **,...);
  8778. -int m_free_vars(MAT **,...);
  8779. -
  8780. -#elif VARARGS
  8781. -/* old varargs is used */
  8782. -
  8783. -#include  <varargs.h>
  8784. -
  8785. -/* prototypes */
  8786. -
  8787. -int v_get_vars();
  8788. -int iv_get_vars();
  8789. -int m_get_vars();
  8790. -int px_get_vars();
  8791. -
  8792. -int v_resize_vars();
  8793. -int iv_resize_vars();
  8794. -int m_resize_vars();
  8795. -int px_resize_vars();
  8796. -
  8797. -int v_free_vars();
  8798. -int iv_free_vars();
  8799. -int px_free_vars();
  8800. -int m_free_vars();
  8801. -
  8802. -#endif
  8803. -
  8804. -
  8805. -#endif
  8806. -
  8807. -
  8808. //GO.SYSIN DD matrix.h
  8809. echo iter.h 1>&2
  8810. sed >iter.h <<'//GO.SYSIN DD iter.h' 's/^-//'
  8811. -
  8812. -/**************************************************************************
  8813. -**
  8814. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  8815. -**
  8816. -**                 Meschach Library
  8817. -** 
  8818. -** This Meschach Library is provided "as is" without any express 
  8819. -** or implied warranty of any kind with respect to this software. 
  8820. -** In particular the authors shall not be liable for any direct, 
  8821. -** indirect, special, incidental or consequential damages arising 
  8822. -** in any way from use of the software.
  8823. -** 
  8824. -** Everyone is granted permission to copy, modify and redistribute this
  8825. -** Meschach Library, provided:
  8826. -**  1.  All copies contain this copyright notice.
  8827. -**  2.  All modified copies shall carry a notice stating who
  8828. -**      made the last modification and the date of such modification.
  8829. -**  3.  No charge is made for this software or works derived from it.  
  8830. -**      This clause shall not be construed as constraining other software
  8831. -**      distributed on the same medium as this software, nor is a
  8832. -**      distribution fee considered a charge.
  8833. -**
  8834. -***************************************************************************/
  8835. -
  8836. -
  8837. -/* iter.h  14/09/93 */
  8838. -
  8839. -/* 
  8840. -
  8841. -  Structures for iterative methods
  8842. -
  8843. -*/
  8844. -
  8845. -#ifndef ITERHH
  8846. -
  8847. -#define ITERHH
  8848. -
  8849. -/* RCS id: $Id: iter.h,v 1.2 1994/03/08 05:48:27 des Exp $  */
  8850. -
  8851. -
  8852. -#include    "sparse.h"
  8853. -
  8854. -
  8855. -/* basic structure for iterative methods */
  8856. -
  8857. -/* type Fun_Ax for functions to get y = A*x */
  8858. -#ifdef ANSI_C
  8859. -typedef VEC  *(*Fun_Ax)(void *,VEC *,VEC *);
  8860. -#else
  8861. -typedef VEC *(*Fun_Ax)();
  8862. -#endif
  8863. -
  8864. -
  8865. -/* type ITER */
  8866. -typedef struct Iter_data {
  8867. -   int shared_x;   /* if TRUE then x is shared and it will not be free'd */ 
  8868. -   int shared_b;   /* if TRUE then b is shared and it will not be free'd */
  8869. -   unsigned k;   /* no. of direction (search) vectors; =0 - none */
  8870. -   int limit;    /* upper bound on the no. of iter. steps */
  8871. -   int steps;    /* no. of iter. steps done */
  8872. -   Real eps;     /* accuracy required */
  8873. -   
  8874. -   VEC *x;       /* input: initial guess;
  8875. -            output: approximate solution */
  8876. -   VEC *b;       /* right hand side of the equation A*x = b */
  8877. -
  8878. -   Fun_Ax   Ax;         /* function computing y = A*x */
  8879. -   void *A_par;         /* parameters for Ax */
  8880. -
  8881. -   Fun_Ax  ATx;         /* function  computing y = A^T*x;
  8882. -                           T = transpose */
  8883. -   void *AT_par;         /* parameters for ATx */
  8884. -
  8885. -   Fun_Ax  Bx; /* function computing y = B*x; B - preconditioner */
  8886. -   void *B_par;         /* parameters for Bx */
  8887. -
  8888. -#ifdef ANSI_C
  8889. -
  8890. -#ifdef PROTOTYPES_IN_STRUCT
  8891. -   void (*info)(struct Iter_data *, double, VEC *,VEC *);
  8892. -            /* function giving some information for a user;
  8893. -           nres - a norm of a residual res */
  8894. -   
  8895. -   int (*stop_crit)(struct Iter_data *, double, VEC *,VEC *);
  8896. -           /* stopping criterion:
  8897. -          nres - a norm of res;
  8898. -          res - residual;
  8899. -        if returned value == TRUE then stop;
  8900. -        if returned value == FALSE then continue; */
  8901. -#else
  8902. -   void (*info)();
  8903. -   int  (*stop_crit)();
  8904. -#endif /* PROTOTYPES_IN_STRUCT */
  8905. -
  8906. -#else
  8907. -
  8908. -   void (*info)();
  8909. -            /* function giving some information for a user */
  8910. -   
  8911. -   int (*stop_crit)();
  8912. -           /* stopping criterion:
  8913. -        if returned value == TRUE then stop;
  8914. -        if returned value == FALSE then continue; */
  8915. -
  8916. -#endif /* ANSI_C */
  8917. -
  8918. -   Real init_res;   /* the norm of the initial residual */
  8919. -
  8920. -}  ITER;
  8921. -
  8922. -
  8923. -#define INULL   (ITER *)NULL
  8924. -
  8925. -/* type Fun_info */
  8926. -#ifdef ANSI_C
  8927. -typedef void (*Fun_info)(ITER *, double, VEC *,VEC *);
  8928. -#else
  8929. -typedef void (*Fun_info)();
  8930. -#endif
  8931. -
  8932. -/* type Fun_stp_crt */
  8933. -#ifdef ANSI_C
  8934. -typedef int (*Fun_stp_crt)(ITER *, double, VEC *,VEC *);
  8935. -#else
  8936. -typedef int (*Fun_stp_crt)();
  8937. -#endif
  8938. -
  8939. -
  8940. -
  8941. -/* macros */
  8942. -/* default values */
  8943. -
  8944. -#define ITER_LIMIT_DEF  1000
  8945. -#define ITER_EPS_DEF    1e-6
  8946. -
  8947. -/* other macros */
  8948. -
  8949. -/* set ip->Ax=fun and ip->A_par=fun_par */
  8950. -#define iter_Ax(ip,fun,fun_par) \
  8951. -  (ip->Ax=(Fun_Ax)(fun),ip->A_par=(void *)(fun_par),0)
  8952. -#define iter_ATx(ip,fun,fun_par) \
  8953. -  (ip->ATx=(Fun_Ax)(fun),ip->AT_par=(void *)(fun_par),0)
  8954. -#define iter_Bx(ip,fun,fun_par) \
  8955. -  (ip->Bx=(Fun_Ax)(fun),ip->B_par=(void *)(fun_par),0)
  8956. -
  8957. -/* save free macro */
  8958. -#define ITER_FREE(ip)  (iter_free(ip), (ip)=(ITER *)NULL)
  8959. -
  8960. -
  8961. -/* prototypes from iter0.c */
  8962. -
  8963. -#ifdef ANSI_C
  8964. -/* standard information */
  8965. -void iter_std_info(ITER *ip,double nres,VEC *res,VEC *Bres);
  8966. -/* standard stopping criterion */
  8967. -int iter_std_stop_crit(ITER *ip, double nres, VEC *res,VEC *Bres);
  8968. -
  8969. -/* get, resize and free ITER variable */
  8970. -ITER *iter_get(int lenb, int lenx);
  8971. -ITER *iter_resize(ITER *ip,int lenb,int lenx);
  8972. -int iter_free(ITER *ip);
  8973. -
  8974. -void iter_dump(FILE *fp,ITER *ip);
  8975. -
  8976. -/* copy ip1 to ip2 copying also elements of x and b */
  8977. -ITER *iter_copy(ITER *ip1, ITER *ip2);
  8978. -/* copy ip1 to ip2 without copying elements of x and b */
  8979. -ITER *iter_copy2(ITER *ip1,ITER *ip2);
  8980. -
  8981. -/* functions for generating sparse matrices with random elements */
  8982. -SPMAT    *iter_gen_sym(int n, int nrow);
  8983. -SPMAT    *iter_gen_nonsym(int m,int n,int nrow,double diag);
  8984. -SPMAT    *iter_gen_nonsym_posdef(int n,int nrow);
  8985. -
  8986. -#else
  8987. -
  8988. -void iter_std_info();
  8989. -int iter_std_stop_crit();
  8990. -ITER *iter_get();
  8991. -int iter_free();
  8992. -ITER *iter_resize();
  8993. -void iter_dump();
  8994. -ITER *iter_copy();
  8995. -ITER *iter_copy2();
  8996. -SPMAT    *iter_gen_sym();
  8997. -SPMAT    *iter_gen_nonsym();
  8998. -SPMAT    *iter_gen_nonsym_posdef();
  8999. -
  9000. -#endif
  9001. -
  9002. -/* prototypes from iter.c */
  9003. -
  9004. -/* different iterative procedures */
  9005. -#ifdef ANSI_C
  9006. -VEC  *iter_cg(ITER *ip);
  9007. -VEC  *iter_cg1(ITER *ip);
  9008. -VEC  *iter_spcg(SPMAT *A,SPMAT *LLT,VEC *b,double eps,VEC *x,int limit,
  9009. -        int *steps);
  9010. -VEC  *iter_cgs(ITER *ip,VEC *r0);
  9011. -VEC  *iter_spcgs(SPMAT *A,SPMAT *B,VEC *b,VEC *r0,double eps,VEC *x,
  9012. -         int limit, int *steps);
  9013. -VEC  *iter_lsqr(ITER *ip);
  9014. -VEC  *iter_splsqr(SPMAT *A,VEC *b,double tol,VEC *x,
  9015. -          int limit,int *steps);
  9016. -VEC  *iter_gmres(ITER *ip);
  9017. -VEC  *iter_spgmres(SPMAT *A,SPMAT *B,VEC *b,double tol,VEC *x,int k,
  9018. -           int limit, int *steps);
  9019. -MAT  *iter_arnoldi_iref(ITER *ip,Real *h,MAT *Q,MAT *H);
  9020. -MAT  *iter_arnoldi(ITER *ip,Real *h,MAT *Q,MAT *H);
  9021. -MAT  *iter_sparnoldi(SPMAT *A,VEC *x0,int k,Real *h,MAT *Q,MAT *H);
  9022. -VEC  *iter_mgcr(ITER *ip);
  9023. -VEC  *iter_spmgcr(SPMAT *A,SPMAT *B,VEC *b,double tol,VEC *x,int k,
  9024. -          int limit, int *steps);
  9025. -void    iter_lanczos(ITER *ip,VEC *a,VEC *b,Real *beta2,MAT *Q);
  9026. -void    iter_splanczos(SPMAT *A,int m,VEC *x0,VEC *a,VEC *b,Real *beta2,
  9027. -               MAT *Q);
  9028. -VEC  *iter_lanczos2(ITER *ip,VEC *evals,VEC *err_est);
  9029. -VEC  *iter_splanczos2(SPMAT *A,int m,VEC *x0,VEC *evals,VEC *err_est);
  9030. -VEC  *iter_cgne(ITER *ip);
  9031. -VEC  *iter_spcgne(SPMAT *A,SPMAT *B,VEC *b,double eps,VEC *x,
  9032. -          int limit,int *steps);
  9033. -#else
  9034. -VEC  *iter_cg();
  9035. -VEC  *iter_cg1();
  9036. -VEC  *iter_spcg();
  9037. -VEC  *iter_cgs();
  9038. -VEC  *iter_spcgs();
  9039. -VEC  *iter_lsqr();
  9040. -VEC  *iter_splsqr();
  9041. -VEC  *iter_gmres();
  9042. -VEC  *iter_spgmres();
  9043. -MAT  *iter_arnoldi_iref();
  9044. -MAT  *iter_arnoldi();
  9045. -MAT  *iter_sparnoldi();
  9046. -VEC  *iter_mgcr();
  9047. -VEC  *iter_spmgcr();
  9048. -void  iter_lanczos();
  9049. -void  iter_splanczos();
  9050. -VEC  *iter_lanczos2();
  9051. -VEC  *iter_splanczos2();
  9052. -VEC  *iter_cgne();
  9053. -VEC  *iter_spcgne();
  9054. -
  9055. -#endif
  9056. -
  9057. -
  9058. -#endif  /* ITERHH */
  9059. //GO.SYSIN DD iter.h
  9060. echo matlab.h 1>&2
  9061. sed >matlab.h <<'//GO.SYSIN DD matlab.h' 's/^-//'
  9062. -
  9063. -/**************************************************************************
  9064. -**
  9065. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  9066. -**
  9067. -**                 Meschach Library
  9068. -** 
  9069. -** This Meschach Library is provided "as is" without any express 
  9070. -** or implied warranty of any kind with respect to this software. 
  9071. -** In particular the authors shall not be liable for any direct, 
  9072. -** indirect, special, incidental or consequential damages arising 
  9073. -** in any way from use of the software.
  9074. -** 
  9075. -** Everyone is granted permission to copy, modify and redistribute this
  9076. -** Meschach Library, provided:
  9077. -**  1.  All copies contain this copyright notice.
  9078. -**  2.  All modified copies shall carry a notice stating who
  9079. -**      made the last modification and the date of such modification.
  9080. -**  3.  No charge is made for this software or works derived from it.  
  9081. -**      This clause shall not be construed as constraining other software
  9082. -**      distributed on the same medium as this software, nor is a
  9083. -**      distribution fee considered a charge.
  9084. -**
  9085. -***************************************************************************/
  9086. -
  9087. -
  9088. -/* matlab.h -- Header file for matlab.c and spmatlab.c for save/load formats */
  9089. -
  9090. -#ifndef MATLAB_DEF
  9091. -
  9092. -#define    MATLAB_DEF
  9093. -
  9094. -/* structure required by MATLAB */
  9095. -typedef struct {
  9096. -    long    type;   /* matrix type */
  9097. -    long    m;      /* # rows */
  9098. -    long    n;      /* # cols */
  9099. -    long    imag;   /* is complex? */
  9100. -    long    namlen; /* length of variable name */
  9101. -        } matlab;
  9102. -
  9103. -/* macros for matrix storage type */
  9104. -#define INTEL   0       /* for 80x87 format */
  9105. -#define PC      INTEL
  9106. -#define MOTOROLA        1       /* 6888x format */
  9107. -#define SUN     MOTOROLA
  9108. -#define APOLLO  MOTOROLA
  9109. -#define MAC     MOTOROLA
  9110. -#define VAX_D   2
  9111. -#define VAX_G   3
  9112. -
  9113. -#define COL_ORDER       0
  9114. -#define ROW_ORDER       1
  9115. -
  9116. -#define DOUBLE_PREC  0       /* double precision */
  9117. -#define SINGLE_PREC  1       /* single precision */
  9118. -#define INT_32  2       /* 32 bit integers (signed) */
  9119. -#define INT_16  3       /* 16 bit integers (signed) */
  9120. -#define INT_16u 4       /* 16 bit integers (unsigned) */
  9121. -/* end of macros for matrix storage type */
  9122. -
  9123. -#ifndef MACH_ID
  9124. -#define MACH_ID         MOTOROLA
  9125. -#endif
  9126. -
  9127. -#define ORDER           ROW_ORDER
  9128. -
  9129. -#if REAL == DOUBLE
  9130. -#define PRECISION       DOUBLE_PREC
  9131. -#elif REAL == FLOAT
  9132. -#define PRECISION      SINGLE_PREC
  9133. -#endif
  9134. -
  9135. -
  9136. -/* prototypes */
  9137. -
  9138. -#ifdef ANSI_C
  9139. -
  9140. -MAT *m_save(FILE *,MAT *,char *);
  9141. -MAT *m_load(FILE *,char **);
  9142. -VEC *v_save(FILE *,VEC *,char *);
  9143. -double d_save(FILE *,double,char *);
  9144. -
  9145. -#else
  9146. -
  9147. -extern    MAT *m_save(), *m_load();
  9148. -extern    VEC *v_save();
  9149. -extern    double d_save();
  9150. -#endif
  9151. -
  9152. -/* complex variant */
  9153. -#ifdef COMPLEX
  9154. -#include "zmatrix.h"
  9155. -
  9156. -#ifdef ANSI_C
  9157. -extern ZMAT    *zm_save(FILE *fp,ZMAT *A,char *name);
  9158. -extern ZVEC    *zv_save(FILE *fp,ZVEC *x,char *name);
  9159. -extern complex    z_save(FILE *fp,complex z,char *name);
  9160. -extern ZMAT    *zm_load(FILE *fp,char **name);
  9161. -
  9162. -#else
  9163. -
  9164. -extern ZMAT    *zm_save();
  9165. -extern ZVEC    *zv_save();
  9166. -extern complex    z_save();
  9167. -extern ZMAT    *zm_load();
  9168. -
  9169. -#endif
  9170. -
  9171. -#endif
  9172. -
  9173. -#endif
  9174. //GO.SYSIN DD matlab.h
  9175. echo matrix2.h 1>&2
  9176. sed >matrix2.h <<'//GO.SYSIN DD matrix2.h' 's/^-//'
  9177. -
  9178. -/**************************************************************************
  9179. -**
  9180. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  9181. -**
  9182. -**                 Meschach Library
  9183. -** 
  9184. -** This Meschach Library is provided "as is" without any express 
  9185. -** or implied warranty of any kind with respect to this software. 
  9186. -** In particular the authors shall not be liable for any direct, 
  9187. -** indirect, special, incidental or consequential damages arising 
  9188. -** in any way from use of the software.
  9189. -** 
  9190. -** Everyone is granted permission to copy, modify and redistribute this
  9191. -** Meschach Library, provided:
  9192. -**  1.  All copies contain this copyright notice.
  9193. -**  2.  All modified copies shall carry a notice stating who
  9194. -**      made the last modification and the date of such modification.
  9195. -**  3.  No charge is made for this software or works derived from it.  
  9196. -**      This clause shall not be construed as constraining other software
  9197. -**      distributed on the same medium as this software, nor is a
  9198. -**      distribution fee considered a charge.
  9199. -**
  9200. -***************************************************************************/
  9201. -
  9202. -
  9203. -/*
  9204. -    Header file for ``matrix2.a'' library file
  9205. -*/
  9206. -
  9207. -
  9208. -#ifndef MATRIX2H
  9209. -#define MATRIX2H
  9210. -
  9211. -#include "matrix.h"
  9212. -
  9213. -/* Unless otherwise specified, factorisation routines overwrite the
  9214. -   matrix that is being factorised */
  9215. -
  9216. -#ifndef ANSI_C
  9217. -
  9218. -extern    MAT    *BKPfactor(), *CHfactor(), *LUfactor(), *QRfactor(),
  9219. -        *QRCPfactor(), *LDLfactor(), *Hfactor(), *MCHfactor(),
  9220. -        *m_inverse();
  9221. -extern    double    LUcondest(), QRcondest();
  9222. -extern    MAT    *makeQ(), *makeR(), *makeHQ(), *makeH();
  9223. -extern    MAT    *LDLupdate(), *QRupdate();
  9224. -
  9225. -extern    VEC    *BKPsolve(), *CHsolve(), *LUsolve(), *_Qsolve(), *QRsolve(),
  9226. -        *LDLsolve(), *Usolve(), *Lsolve(), *Dsolve(), *LTsolve(),
  9227. -        *UTsolve(), *LUTsolve(), *QRCPsolve();
  9228. -
  9229. -extern  BAND    *bdLUfactor(), *bdLDLfactor();
  9230. -extern  VEC     *bdLUsolve(), *bdLDLsolve();
  9231. -
  9232. -extern    VEC    *hhvec();
  9233. -extern    VEC    *hhtrvec();
  9234. -extern    MAT    *hhtrrows();
  9235. -extern    MAT    *hhtrcols();
  9236. -
  9237. -extern    void    givens();
  9238. -extern    VEC    *rot_vec();    /* in situ */
  9239. -extern    MAT    *rot_rows();    /* in situ */
  9240. -extern    MAT    *rot_cols();    /* in situ */
  9241. -
  9242. -
  9243. -/* eigenvalue routines */
  9244. -extern    VEC    *trieig(), *symmeig();
  9245. -extern    MAT    *schur();
  9246. -extern    void    schur_evals();
  9247. -extern    MAT    *schur_vecs();
  9248. -
  9249. -/* singular value decomposition */
  9250. -extern    VEC    *bisvd(), *svd();
  9251. -
  9252. -/* matrix powers and exponent */
  9253. -MAT  *_m_pow();
  9254. -MAT  *m_pow();
  9255. -MAT  *m_exp(), *_m_exp();
  9256. -MAT  *m_poly();
  9257. -
  9258. -/* FFT */
  9259. -void fft();
  9260. -void ifft();
  9261. -
  9262. -
  9263. -#else
  9264. -
  9265. -                 /* forms Bunch-Kaufman-Parlett factorisation for
  9266. -                        symmetric indefinite matrices */
  9267. -extern    MAT    *BKPfactor(MAT *A,PERM *pivot,PERM *blocks),
  9268. -                 /* Cholesky factorisation of A
  9269. -                        (symmetric, positive definite) */
  9270. -        *CHfactor(MAT *A),
  9271. -                /* LU factorisation of A (with partial pivoting) */ 
  9272. -                *LUfactor(MAT *A,PERM *pivot),
  9273. -                /* QR factorisation of A; need dim(diag) >= # rows of A */
  9274. -        *QRfactor(MAT *A,VEC *diag),
  9275. -                /* QR factorisation of A with column pivoting */
  9276. -        *QRCPfactor(MAT *A,VEC *diag,PERM *pivot),
  9277. -                /* L.D.L^T factorisation of A */
  9278. -        *LDLfactor(MAT *A), 
  9279. -                /* Hessenberg factorisation of A -- for schur() */
  9280. -                *Hfactor(MAT *A,VEC *diag1,VEC *diag2),
  9281. -                /* modified Cholesky factorisation of A;
  9282. -                        actually factors A+D, D diagonal with no
  9283. -                        diagonal entry in the factor < sqrt(tol) */
  9284. -                *MCHfactor(MAT *A,double tol),
  9285. -        *m_inverse(MAT *A,MAT *out);
  9286. -
  9287. -                /* returns condition estimate for A after LUfactor() */
  9288. -extern    double    LUcondest(MAT *A,PERM *pivot),
  9289. -                /* returns condition estimate for Q after QRfactor() */
  9290. -                QRcondest(MAT *A);
  9291. -
  9292. -/* Note: The make..() and ..update() routines assume that the factorisation
  9293. -        has already been carried out */
  9294. -
  9295. -     /* Qout is the "Q" (orthongonal) matrix from QR factorisation */
  9296. -extern    MAT    *makeQ(MAT *A,VEC *diag,MAT *Qout),
  9297. -                /* Rout is the "R" (upper triangular) matrix
  9298. -                        from QR factorisation */
  9299. -        *makeR(MAT *A,MAT *Rout),
  9300. -                /* Qout is orthogonal matrix in Hessenberg factorisation */
  9301. -        *makeHQ(MAT *A,VEC *diag1,VEC *diag2,MAT *Qout),
  9302. -                /* Hout is the Hessenberg matrix in Hessenberg factorisation */
  9303. -        *makeH(MAT *A,MAT *Hout);
  9304. -
  9305. -                /* updates L.D.L^T factorisation for A <- A + alpha.u.u^T */
  9306. -extern    MAT    *LDLupdate(MAT *A,VEC *u,double alpha),
  9307. -                /* updates QR factorisation for QR <- Q.(R+u.v^T)
  9308. -           Note: we need explicit Q & R matrices,
  9309. -                        from makeQ() and makeR() */
  9310. -        *QRupdate(MAT *Q,MAT *R,VEC *u,VEC *v);
  9311. -
  9312. -/* Solve routines assume that the corresponding factorisation routine
  9313. -        has already been applied to the matrix along with auxiliary
  9314. -        objects (such as pivot permutations)
  9315. -
  9316. -        These solve the system A.x = b,
  9317. -        except for LUTsolve and QRTsolve which solve the transposed system
  9318. -                                A^T.x. = b.
  9319. -        If x is NULL on entry, then it is created.
  9320. -*/
  9321. -
  9322. -extern    VEC    *BKPsolve(MAT *A,PERM *pivot,PERM *blocks,VEC *b,VEC *x),
  9323. -        *CHsolve(MAT *A,VEC *b,VEC *x),
  9324. -        *LDLsolve(MAT *A,VEC *b,VEC *x),
  9325. -        *LUsolve(MAT *A,PERM *pivot,VEC *b,VEC *x),
  9326. -        *_Qsolve(MAT *A,VEC *,VEC *,VEC *, VEC *),
  9327. -        *QRsolve(MAT *A,VEC *,VEC *b,VEC *x),
  9328. -            *QRTsolve(MAT *A,VEC *,VEC *b,VEC *x),
  9329. -
  9330. -
  9331. -     /* Triangular equations solve routines;
  9332. -        U for upper triangular, L for lower traingular, D for diagonal
  9333. -        if diag_val == 0.0 use that values in the matrix */
  9334. -
  9335. -        *Usolve(MAT *A,VEC *b,VEC *x,double diag_val),
  9336. -        *Lsolve(MAT *A,VEC *b,VEC *x,double diag_val),
  9337. -        *Dsolve(MAT *A,VEC *b,VEC *x),
  9338. -        *LTsolve(MAT *A,VEC *b,VEC *x,double diag_val),
  9339. -        *UTsolve(MAT *A,VEC *b,VEC *x,double diag_val),
  9340. -                *LUTsolve(MAT *A,PERM *,VEC *,VEC *),
  9341. -                *QRCPsolve(MAT *QR,VEC *diag,PERM *pivot,VEC *b,VEC *x);
  9342. -
  9343. -extern  BAND    *bdLUfactor(BAND *A,PERM *pivot),
  9344. -                *bdLDLfactor(BAND *A);
  9345. -extern  VEC     *bdLUsolve(BAND *A,PERM *pivot,VEC *b,VEC *x),
  9346. -                *bdLDLsolve(BAND *A,VEC *b,VEC *x);
  9347. -
  9348. -
  9349. -
  9350. -extern    VEC    *hhvec(VEC *,u_int,Real *,VEC *,Real *);
  9351. -extern    VEC    *hhtrvec(VEC *,double,u_int,VEC *,VEC *);
  9352. -extern    MAT    *hhtrrows(MAT *,u_int,u_int,VEC *,double);
  9353. -extern    MAT    *hhtrcols(MAT *,u_int,u_int,VEC *,double);
  9354. -
  9355. -extern    void    givens(double,double,Real *,Real *);
  9356. -extern    VEC    *rot_vec(VEC *,u_int,u_int,double,double,VEC *); /* in situ */
  9357. -extern    MAT    *rot_rows(MAT *,u_int,u_int,double,double,MAT *); /* in situ */
  9358. -extern    MAT    *rot_cols(MAT *,u_int,u_int,double,double,MAT *); /* in situ */
  9359. -
  9360. -
  9361. -/* eigenvalue routines */
  9362. -
  9363. -               /* compute eigenvalues of tridiagonal matrix
  9364. -                  with diagonal entries a[i], super & sub diagonal entries
  9365. -                  b[i]; eigenvectors stored in Q (if not NULL) */
  9366. -extern    VEC    *trieig(VEC *a,VEC *b,MAT *Q),
  9367. -                 /* sets out to be vector of eigenvectors; eigenvectors
  9368. -                   stored in Q (if not NULL). A is unchanged */
  9369. -        *symmeig(MAT *A,MAT *Q,VEC *out);
  9370. -
  9371. -               /* computes real Schur form = Q^T.A.Q */
  9372. -extern    MAT    *schur(MAT *A,MAT *Q);
  9373. -         /* computes real and imaginary parts of the eigenvalues
  9374. -                        of A after schur() */
  9375. -extern    void    schur_evals(MAT *A,VEC *re_part,VEC *im_part);
  9376. -          /* computes real and imaginary parts of the eigenvectors
  9377. -                        of A after schur() */
  9378. -extern    MAT    *schur_vecs(MAT *T,MAT *Q,MAT *X_re,MAT *X_im);
  9379. -
  9380. -
  9381. -/* singular value decomposition */
  9382. -
  9383. -        /* computes singular values of bi-diagonal matrix with
  9384. -                   diagonal entries a[i] and superdiagonal entries b[i];
  9385. -                   singular vectors stored in U and V (if not NULL) */
  9386. -VEC    *bisvd(VEC *a,VEC *b,MAT *U,MAT *V),
  9387. -               /* sets out to be vector of singular values;
  9388. -                   singular vectors stored in U and V */
  9389. -    *svd(MAT *A,MAT *U,MAT *V,VEC *out);
  9390. -
  9391. -/* matrix powers and exponent */
  9392. -MAT  *_m_pow(MAT *,int,MAT *,MAT *);
  9393. -MAT  *m_pow(MAT *,int, MAT *);
  9394. -MAT  *m_exp(MAT *,double,MAT *);
  9395. -MAT  *_m_exp(MAT *,double,MAT *,int *,int *);
  9396. -MAT  *m_poly(MAT *,VEC *,MAT *);
  9397. -
  9398. -/* FFT */
  9399. -void fft(VEC *,VEC *);
  9400. -void ifft(VEC *,VEC *);
  9401. -
  9402. -#endif
  9403. -
  9404. -
  9405. -#endif
  9406. //GO.SYSIN DD matrix2.h
  9407. echo oldnames.h 1>&2
  9408. sed >oldnames.h <<'//GO.SYSIN DD oldnames.h' 's/^-//'
  9409. -
  9410. -/**************************************************************************
  9411. -**
  9412. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  9413. -**
  9414. -**                 Meschach Library
  9415. -** 
  9416. -** This Meschach Library is provided "as is" without any express 
  9417. -** or implied warranty of any kind with respect to this software. 
  9418. -** In particular the authors shall not be liable for any direct, 
  9419. -** indirect, special, incidental or consequential damages arising 
  9420. -** in any way from use of the software.
  9421. -** 
  9422. -** Everyone is granted permission to copy, modify and redistribute this
  9423. -** Meschach Library, provided:
  9424. -**  1.  All copies contain this copyright notice.
  9425. -**  2.  All modified copies shall carry a notice stating who
  9426. -**      made the last modification and the date of such modification.
  9427. -**  3.  No charge is made for this software or works derived from it.  
  9428. -**      This clause shall not be construed as constraining other software
  9429. -**      distributed on the same medium as this software, nor is a
  9430. -**      distribution fee considered a charge.
  9431. -**
  9432. -***************************************************************************/
  9433. -
  9434. -
  9435. -/* macros for names used in versions 1.0 and 1.1 */
  9436. -/* 8/11/93 */
  9437. -
  9438. -
  9439. -#ifndef OLDNAMESH
  9440. -#define OLDNAMESH
  9441. -
  9442. -
  9443. -/* type IVEC */
  9444. -
  9445. -#define get_ivec   iv_get
  9446. -#define freeivec   IV_FREE
  9447. -#define cp_ivec    iv_copy
  9448. -#define fout_ivec  iv_foutput
  9449. -#define out_ivec   iv_output
  9450. -#define fin_ivec   iv_finput
  9451. -#define in_ivec    iv_input
  9452. -#define dump_ivec  iv_dump
  9453. -
  9454. -
  9455. -/* type ZVEC */
  9456. -
  9457. -#define get_zvec   zv_get
  9458. -#define freezvec   ZV_FREE
  9459. -#define cp_zvec    zv_copy
  9460. -#define fout_zvec  zv_foutput
  9461. -#define out_zvec   zv_output
  9462. -#define fin_zvec   zv_finput
  9463. -#define in_zvec    zv_input
  9464. -#define zero_zvec  zv_zero
  9465. -#define rand_zvec  zv_rand
  9466. -#define dump_zvec  zv_dump
  9467. -
  9468. -/* type ZMAT */
  9469. -
  9470. -#define get_zmat   zm_get
  9471. -#define freezmat   ZM_FREE
  9472. -#define cp_zmat    zm_copy
  9473. -#define fout_zmat  zm_foutput
  9474. -#define out_zmat   zm_output
  9475. -#define fin_zmat   zm_finput
  9476. -#define in_zmat    zm_input
  9477. -#define zero_zmat  zm_zero
  9478. -#define rand_zmat  zm_rand
  9479. -#define dump_zmat  zm_dump
  9480. -
  9481. -/* types SPMAT */
  9482. -
  9483. -#define sp_mat        SPMAT
  9484. -#define sp_get_mat    sp_get
  9485. -#define sp_free_mat   sp_free
  9486. -#define sp_cp_mat     sp_copy
  9487. -#define sp_cp_mat2    sp_copy2
  9488. -#define sp_fout_mat   sp_foutput
  9489. -#define sp_fout_mat2  sp_foutput2
  9490. -#define sp_out_mat    sp_output
  9491. -#define sp_out_mat2   sp_output2
  9492. -#define sp_fin_mat    sp_finput
  9493. -#define sp_in_mat     sp_input
  9494. -#define sp_zero_mat   sp_zero
  9495. -#define sp_dump_mat   sp_dump
  9496. -
  9497. -
  9498. -/* type SPROW */
  9499. -
  9500. -#define sp_row        SPROW
  9501. -#define sp_get_idx    sprow_idx
  9502. -#define row_xpd       sprow_xpd
  9503. -#define sp_get_row    sprow_get
  9504. -#define row_set_val   sprow_set_val
  9505. -#define fout_row      sprow_foutput
  9506. -#define _row_mltadd   sprow_mltadd
  9507. -#define sp_row_copy   sprow_copy
  9508. -#define sp_row_merge  sprow_merge
  9509. -#define sp_row_ip     sprow_ip
  9510. -#define sp_row_sqr    sprow_sqr
  9511. -
  9512. -
  9513. -/* type MAT */
  9514. -
  9515. -#define get_mat   m_get
  9516. -#define freemat   M_FREE
  9517. -#define cp_mat    m_copy
  9518. -#define fout_mat  m_foutput
  9519. -#define out_mat   m_output
  9520. -#define fin_mat   m_finput
  9521. -#define in_mat    m_input
  9522. -#define zero_mat  m_zero
  9523. -#define id_mat    m_ident
  9524. -#define rand_mat  m_rand
  9525. -#define ones_mat  m_ones
  9526. -#define dump_mat  m_dump
  9527. -
  9528. -/* type VEC */
  9529. -
  9530. -#define get_vec   v_get
  9531. -#define freevec   V_FREE
  9532. -#define cp_vec    v_copy
  9533. -#define fout_vec  v_foutput
  9534. -#define out_vec   v_output
  9535. -#define fin_vec   v_finput
  9536. -#define in_vec    v_input
  9537. -#define zero_vec  v_zero
  9538. -#define rand_vec  v_rand
  9539. -#define ones_vec  v_ones
  9540. -#define dump_vec  v_dump
  9541. -
  9542. -
  9543. -/* type PERM */
  9544. -
  9545. -#define get_perm   px_get
  9546. -#define freeperm   PX_FREE
  9547. -#define cp_perm    px_copy
  9548. -#define fout_perm  px_foutput
  9549. -#define out_perm   px_output
  9550. -#define fin_perm   px_finput
  9551. -#define in_perm    px_input
  9552. -#define id_perm    px_ident
  9553. -#define px_id      px_ident
  9554. -#define trans_px   px_transp
  9555. -#define sign_px    px_sign
  9556. -#define dump_perm  px_dump
  9557. -
  9558. -#endif
  9559. //GO.SYSIN DD oldnames.h
  9560. echo sparse.h 1>&2
  9561. sed >sparse.h <<'//GO.SYSIN DD sparse.h' 's/^-//'
  9562. -
  9563. -/**************************************************************************
  9564. -**
  9565. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  9566. -**
  9567. -**                 Meschach Library
  9568. -** 
  9569. -** This Meschach Library is provided "as is" without any express 
  9570. -** or implied warranty of any kind with respect to this software. 
  9571. -** In particular the authors shall not be liable for any direct, 
  9572. -** indirect, special, incidental or consequential damages arising 
  9573. -** in any way from use of the software.
  9574. -** 
  9575. -** Everyone is granted permission to copy, modify and redistribute this
  9576. -** Meschach Library, provided:
  9577. -**  1.  All copies contain this copyright notice.
  9578. -**  2.  All modified copies shall carry a notice stating who
  9579. -**      made the last modification and the date of such modification.
  9580. -**  3.  No charge is made for this software or works derived from it.  
  9581. -**      This clause shall not be construed as constraining other software
  9582. -**      distributed on the same medium as this software, nor is a
  9583. -**      distribution fee considered a charge.
  9584. -**
  9585. -***************************************************************************/
  9586. -
  9587. -
  9588. -/*
  9589. -    Header for sparse matrix stuff.
  9590. -    Basic sparse routines to be held in sparse.c
  9591. -*/
  9592. -
  9593. -/* RCS id: $Id: sparse.h,v 1.2 1994/01/13 05:33:36 des Exp $ */
  9594. -
  9595. -#ifndef SPARSEH
  9596. -
  9597. -#define SPARSEH 
  9598. -
  9599. -
  9600. -#include        "matrix.h"
  9601. -
  9602. -
  9603. -/* basic sparse types */
  9604. -
  9605. -typedef struct row_elt    {
  9606. -    int    col, nxt_row, nxt_idx;
  9607. -    Real    val;
  9608. -        } row_elt;
  9609. -
  9610. -typedef struct SPROW {
  9611. -    int    len, maxlen, diag;
  9612. -    row_elt    *elt;        /* elt[maxlen] */
  9613. -        } SPROW;
  9614. -
  9615. -typedef struct SPMAT {
  9616. -    int    m, n, max_m, max_n;
  9617. -    char    flag_col, flag_diag;
  9618. -    SPROW    *row;        /* row[max_m] */
  9619. -    int    *start_row;    /* start_row[max_n] */
  9620. -    int    *start_idx;    /* start_idx[max_n] */
  9621. -          } SPMAT;
  9622. -
  9623. -/* Note that the first allocated entry in column j is start_row[j];
  9624. -    This starts the chain down the columns using the nxt_row and nxt_idx
  9625. -    fields of each entry in each row. */
  9626. -
  9627. -typedef struct pair { int pos;    Real val; } pair;
  9628. -
  9629. -typedef struct SPVEC {
  9630. -    int    dim, max_dim;
  9631. -    pair    *elt;        /* elt[max_dim] */
  9632. -           } SPVEC;
  9633. -
  9634. -#define    SMNULL    ((SPMAT*)NULL)
  9635. -#define    SVNULL    ((SPVEC*)NULL)
  9636. -
  9637. -/* Macro for speedup */
  9638. -#define    sprow_idx2(r,c,hint)    \
  9639. -    ( ( (hint) >= 0 && (hint) < (r)->len && \
  9640. -       (r)->elt[hint].col == (c)) ? (hint) : sprow_idx((r),(c)) )
  9641. -
  9642. -
  9643. -
  9644. -/* memory functions */
  9645. -
  9646. -#ifdef ANSI_C
  9647. -int sp_get_vars(int m,int n,int deg,...);
  9648. -int sp_resize_vars(int m,int n,...);
  9649. -int sp_free_vars(SPMAT **,...);
  9650. -#elif VARARGS
  9651. -int sp_get_vars();
  9652. -int sp_resize_vars();
  9653. -int sp_free_vars();
  9654. -
  9655. -#endif
  9656. -
  9657. -/* Sparse Matrix Operations and Utilities */
  9658. -#ifndef ANSI_C
  9659. -extern    SPMAT    *sp_get(), *sp_copy(), *sp_copy2(),
  9660. -            *sp_zero(), *sp_resize(), *sp_compact();
  9661. -extern    double    sp_get_val(), sp_set_val();
  9662. -extern    VEC    *sp_mv_mlt(), *sp_vm_mlt();
  9663. -extern    int    sp_free();
  9664. -
  9665. -/* Access path operations */
  9666. -extern    SPMAT    *sp_col_access();
  9667. -extern    SPMAT    *sp_diag_access();
  9668. -extern  int     chk_col_access();
  9669. -
  9670. -/* Input/output operations */
  9671. -extern    SPMAT    *sp_finput();
  9672. -extern    void sp_foutput(), sp_foutput2();
  9673. -
  9674. -/* algebraic operations */
  9675. -extern SPMAT *sp_smlt(), *sp_add(), *sp_sub(), *sp_mltadd();
  9676. -
  9677. -
  9678. -/* sparse row operations */
  9679. -extern    SPROW    *sprow_get(), *sprow_xpd(), *sprow_merge(), *sprow_mltadd(),
  9680. -  *sprow_resize(), *sprow_copy();
  9681. -extern SPROW *sprow_add(), *sprow_sub(), *sprow_smlt();
  9682. -extern    double    sprow_set_val();
  9683. -extern    void    sprow_foutput();
  9684. -extern    int    sprow_idx(), sprow_free();
  9685. -
  9686. -/* dump */
  9687. -extern  void   sp_dump(), sprow_dump();
  9688. -extern  MAT  *sp_m2dense();
  9689. -
  9690. -#else
  9691. -SPMAT    *sp_get(int,int,int), *sp_copy(SPMAT *),
  9692. -    *sp_copy2(SPMAT *,SPMAT *),
  9693. -    *sp_zero(SPMAT *), *sp_resize(SPMAT *,int,int),
  9694. -    *sp_compact(SPMAT *,double);
  9695. -double    sp_get_val(SPMAT *,int,int), sp_set_val(SPMAT *,int,int,double);
  9696. -VEC    *sp_mv_mlt(SPMAT *,VEC *,VEC *), *sp_vm_mlt(SPMAT *,VEC *,VEC *);
  9697. -int    sp_free(SPMAT *);
  9698. -
  9699. -/* Access path operations */
  9700. -SPMAT    *sp_col_access(SPMAT *);
  9701. -SPMAT    *sp_diag_access(SPMAT *);
  9702. -int     chk_col_access(SPMAT *);
  9703. -
  9704. -/* Input/output operations */
  9705. -SPMAT    *sp_finput(FILE *);
  9706. -void    sp_foutput(FILE *,SPMAT *), sp_foutput2(FILE *,SPMAT *);
  9707. -
  9708. -/* algebraic operations */
  9709. -SPMAT *sp_smlt(SPMAT *A,double alpha,SPMAT *B),
  9710. -      *sp_add(SPMAT *A,SPMAT *B,SPMAT *C),
  9711. -      *sp_sub(SPMAT *A,SPMAT *B,SPMAT *C),
  9712. -      *sp_mltadd(SPMAT *A,SPMAT *B,double alpha,SPMAT *C);
  9713. -
  9714. -/* sparse row operations */
  9715. -SPROW    *sprow_get(int), *sprow_xpd(SPROW *r,int n,int type),
  9716. -        *sprow_resize(SPROW *r,int n,int type),
  9717. -    *sprow_merge(SPROW *,SPROW *,SPROW *,int type),
  9718. -        *sprow_copy(SPROW *,SPROW *,SPROW *,int type),
  9719. -    *sprow_mltadd(SPROW *,SPROW *,double,int,SPROW *,int type);
  9720. -SPROW *sprow_add(SPROW *r1,SPROW *r2, int j0,SPROW *r_out, int type), 
  9721. -        *sprow_sub(SPROW *r1,SPROW *r2, int j0,SPROW *r_out, int type), 
  9722. -        *sprow_smlt(SPROW *r1,double alpha, int j0,SPROW *r_out, int type);
  9723. -double    sprow_set_val(SPROW *,int,double);
  9724. -int      sprow_free(SPROW *);
  9725. -int    sprow_idx(SPROW *,int);
  9726. -void    sprow_foutput(FILE *,SPROW *);
  9727. -
  9728. -/* dump */
  9729. -void    sp_dump(FILE *fp, SPMAT *A);
  9730. -void    sprow_dump(FILE *fp, SPROW *r);
  9731. -MAT    *sp_m2dense(SPMAT *A,MAT *out);
  9732. -
  9733. -#endif
  9734. -
  9735. -/* MACROS */
  9736. -
  9737. -#define    sp_input()    sp_finput(stdin)
  9738. -#define    sp_output(A)    sp_foutput(stdout,(A))
  9739. -#define    sp_output2(A)    sp_foutput2(stdout,(A))
  9740. -#define    row_mltadd(r1,r2,alpha,out)    sprow_mltadd(r1,r2,alpha,0,out)
  9741. -#define    out_row(r)    sprow_foutput(stdout,(r))
  9742. -
  9743. -#define SP_FREE(A)    ( sp_free((A)),  (A)=(SPMAT *)NULL) 
  9744. -
  9745. -/* utility for index computations -- ensures index returned >= 0 */
  9746. -#define    fixindex(idx)    ((idx) == -1 ? (error(E_BOUNDS,"fixindex"),0) : \
  9747. -             (idx) < 0 ? -((idx)+2) : (idx))
  9748. -
  9749. -
  9750. -/*  NOT USED */
  9751. -
  9752. -/* loop over the columns in a row */
  9753. -/*
  9754. -#define    loop_cols(r,e,code) \
  9755. -    do { int _r_idx; row_elt *e; SPROW *_t_row;            \
  9756. -      _t_row = (r); e = &(_t_row->elt);                \
  9757. -      for ( _r_idx = 0; _r_idx < _t_row->len; _r_idx++, e++ )    \
  9758. -      {  code;  }  }  while ( 0 )
  9759. -*/
  9760. -/* loop over the rows in a column */
  9761. -/*
  9762. -#define    loop_cols(A,col,e,code) \
  9763. -    do { int _r_num, _r_idx, _c; SPROW *_r; row_elt *e;        \
  9764. -      if ( ! (A)->flag_col )    sp_col_access((A));        \
  9765. -      col_num = (col);                        \
  9766. -      if ( col_num < 0 || col_num >= A->n )                \
  9767. -          error(E_BOUNDS,"loop_cols");                \
  9768. -          _r_num = (A)->start_row[_c]; _r_idx = (A)->start_idx[_c];    \
  9769. -      while ( _r_num >= 0 )  {                    \
  9770. -          _r = &((A)->row[_r_num]);                    \
  9771. -              _r_idx = sprow_idx2(_r,_c,_r_idx);            \
  9772. -              if ( _r_idx < 0 )  continue;                \
  9773. -          e = &(_r->elt[_r_idx]);    code;                \
  9774. -          _r_num = e->nxt_row;    _r_idx = e->nxt_idx;        \
  9775. -          } } while ( 0 )
  9776. -
  9777. -*/
  9778. -
  9779. -#endif
  9780. -
  9781. //GO.SYSIN DD sparse.h
  9782. echo sparse2.h 1>&2
  9783. sed >sparse2.h <<'//GO.SYSIN DD sparse2.h' 's/^-//'
  9784. -
  9785. -/**************************************************************************
  9786. -**
  9787. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  9788. -**
  9789. -**                 Meschach Library
  9790. -** 
  9791. -** This Meschach Library is provided "as is" without any express 
  9792. -** or implied warranty of any kind with respect to this software. 
  9793. -** In particular the authors shall not be liable for any direct, 
  9794. -** indirect, special, incidental or consequential damages arising 
  9795. -** in any way from use of the software.
  9796. -** 
  9797. -** Everyone is granted permission to copy, modify and redistribute this
  9798. -** Meschach Library, provided:
  9799. -**  1.  All copies contain this copyright notice.
  9800. -**  2.  All modified copies shall carry a notice stating who
  9801. -**      made the last modification and the date of such modification.
  9802. -**  3.  No charge is made for this software or works derived from it.  
  9803. -**      This clause shall not be construed as constraining other software
  9804. -**      distributed on the same medium as this software, nor is a
  9805. -**      distribution fee considered a charge.
  9806. -**
  9807. -***************************************************************************/
  9808. -
  9809. -
  9810. -/* Sparse matrix factorise/solve header */
  9811. -/* RCS id: $Id: sparse2.h,v 1.4 1994/01/13 05:33:46 des Exp $ */
  9812. -
  9813. -
  9814. -
  9815. -#ifndef SPARSE2H
  9816. -
  9817. -#define SPARSE2H
  9818. -
  9819. -#include "sparse.h"
  9820. -
  9821. -
  9822. -#ifdef ANSI_C
  9823. -SPMAT    *spCHfactor(SPMAT *), *spICHfactor(SPMAT *), *spCHsymb(SPMAT *);
  9824. -VEC    *spCHsolve(SPMAT *,VEC *,VEC *);
  9825. -
  9826. -SPMAT    *spLUfactor(SPMAT *,PERM *,double);
  9827. -SPMAT    *spILUfactor(SPMAT *,double);
  9828. -VEC    *spLUsolve(SPMAT *,PERM *,VEC *,VEC *),
  9829. -    *spLUTsolve(SPMAT *,PERM *,VEC *,VEC *);
  9830. -
  9831. -SPMAT    *spBKPfactor(SPMAT *, PERM *, PERM *, double);
  9832. -VEC    *spBKPsolve(SPMAT *, PERM *, PERM *, VEC *, VEC *);
  9833. -
  9834. -VEC    *pccg(VEC *(*A)(),void *A_par,VEC *(*M_inv)(),void *M_par,VEC *b,
  9835. -                        double tol,VEC *x);
  9836. -VEC    *sp_pccg(SPMAT *,SPMAT *,VEC *,double,VEC *);
  9837. -VEC    *cgs(VEC *(*A)(),void *A_par,VEC *b,VEC *r0,double tol,VEC *x);
  9838. -VEC    *sp_cgs(SPMAT *,VEC *,VEC *,double,VEC *);
  9839. -VEC    *lsqr(VEC *(*A)(),VEC *(*AT)(),void *A_par,VEC *b,double tol,VEC *x);
  9840. -VEC    *sp_lsqr(SPMAT *,VEC *,double,VEC *);
  9841. -int    cg_set_maxiter(int);
  9842. -
  9843. -void    lanczos(VEC *(*A)(),void *A_par,int m,VEC *x0,VEC *a,VEC *b,
  9844. -                        Real *beta_m1,MAT *Q);
  9845. -void    sp_lanczos(SPMAT *,int,VEC *,VEC *,VEC *,Real *,MAT *);
  9846. -VEC    *lanczos2(VEC *(*A)(),void *A_par,int m,VEC *x0,VEC *evals,
  9847. -                        VEC *err_est);
  9848. -VEC    *sp_lanczos2(SPMAT *,int,VEC *,VEC *,VEC *);
  9849. -extern  void    scan_to(SPMAT *,IVEC *,IVEC *,IVEC *,int);
  9850. -extern  row_elt  *chase_col(SPMAT *,int,int *,int *,int);
  9851. -extern  row_elt  *chase_past(SPMAT *,int,int *,int *,int);
  9852. -extern  row_elt  *bump_col(SPMAT *,int,int *,int *);
  9853. -
  9854. -#else
  9855. -extern SPMAT    *spCHfactor(), *spICHfactor(), *spCHsymb();
  9856. -extern VEC    *spCHsolve();
  9857. -
  9858. -extern SPMAT    *spLUfactor();
  9859. -extern SPMAT    *spILUfactor();
  9860. -extern VEC    *spLUsolve(), *spLUTsolve();
  9861. -
  9862. -extern SPMAT    *spBKPfactor();
  9863. -extern VEC    *spBKPsolve();
  9864. -
  9865. -extern VEC    *pccg(), *sp_pccg(), *cgs(), *sp_cgs(), *lsqr(), *sp_lsqr();
  9866. -extern int    cg_set_maxiter();
  9867. -
  9868. -void    lanczos(), sp_lanczos();
  9869. -VEC    *lanczos2(), *sp_lanczos2();
  9870. -extern  void    scan_to();
  9871. -extern  row_elt  *chase_col();
  9872. -extern  row_elt  *chase_past();
  9873. -extern  row_elt  *bump_col();
  9874. -
  9875. -#endif
  9876. -
  9877. -
  9878. -#endif
  9879. //GO.SYSIN DD sparse2.h
  9880. echo zmatrix.h 1>&2
  9881. sed >zmatrix.h <<'//GO.SYSIN DD zmatrix.h' 's/^-//'
  9882. -
  9883. -/**************************************************************************
  9884. -**
  9885. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  9886. -**
  9887. -**                 Meschach Library
  9888. -** 
  9889. -** This Meschach Library is provided "as is" without any express 
  9890. -** or implied warranty of any kind with respect to this software. 
  9891. -** In particular the authors shall not be liable for any direct, 
  9892. -** indirect, special, incidental or consequential damages arising 
  9893. -** in any way from use of the software.
  9894. -** 
  9895. -** Everyone is granted permission to copy, modify and redistribute this
  9896. -** Meschach Library, provided:
  9897. -**  1.  All copies contain this copyright notice.
  9898. -**  2.  All modified copies shall carry a notice stating who
  9899. -**      made the last modification and the date of such modification.
  9900. -**  3.  No charge is made for this software or works derived from it.  
  9901. -**      This clause shall not be construed as constraining other software
  9902. -**      distributed on the same medium as this software, nor is a
  9903. -**      distribution fee considered a charge.
  9904. -**
  9905. -***************************************************************************/
  9906. -
  9907. -
  9908. -/* Main include file for zmeschach library -- complex vectors and matrices */
  9909. -
  9910. -#ifndef ZMATRIXH
  9911. -#define ZMATRIXH
  9912. -
  9913. -#include "matrix.h"
  9914. -
  9915. -
  9916. -          /*  Type definitions for complex vectors and matrices  */
  9917. -
  9918. -
  9919. -/* complex definition */
  9920. -typedef struct  {
  9921. -                Real re,im;
  9922. -        } complex;
  9923. -
  9924. -/* complex vector definition */
  9925. -typedef struct  {
  9926. -                u_int   dim, max_dim;
  9927. -                complex  *ve;
  9928. -                } ZVEC;
  9929. -
  9930. -/* complex matrix definition */
  9931. -typedef struct  {
  9932. -                u_int   m, n;
  9933. -                u_int   max_m, max_n, max_size;
  9934. -                complex *base;          /* base is base of alloc'd mem */
  9935. -                complex **me;
  9936. -                } ZMAT;
  9937. -
  9938. -#define ZVNULL  ((ZVEC *)NULL)
  9939. -#define ZMNULL  ((ZMAT *)NULL)
  9940. -
  9941. -#define    Z_CONJ        1
  9942. -#define    Z_NOCONJ    0
  9943. -
  9944. -
  9945. -/* memory functions */
  9946. -
  9947. -#ifdef ANSI_C
  9948. -int zv_get_vars(int dim,...);
  9949. -int zm_get_vars(int m,int n,...);
  9950. -int zv_resize_vars(int new_dim,...);
  9951. -int zm_resize_vars(int m,int n,...);
  9952. -int zv_free_vars(ZVEC **,...);
  9953. -int zm_free_vars(ZMAT **,...);
  9954. -
  9955. -#elif VARARGS
  9956. -int zv_get_vars();
  9957. -int zm_get_vars();
  9958. -int zv_resize_vars();
  9959. -int zm_resize_vars();
  9960. -int zv_free_vars();
  9961. -int zm_free_vars();
  9962. -
  9963. -#endif
  9964. -
  9965. -
  9966. -
  9967. -
  9968. -#ifdef ANSI_C
  9969. -extern ZMAT    *_zm_copy(ZMAT *in,ZMAT *out,u_int i0,u_int j0);
  9970. -extern ZMAT    * zm_move(ZMAT *, int, int, int, int, ZMAT *, int, int);
  9971. -extern ZMAT    *zvm_move(ZVEC *, int, ZMAT *, int, int, int, int);
  9972. -extern ZVEC    *_zv_copy(ZVEC *in,ZVEC *out,u_int i0);
  9973. -extern ZVEC    * zv_move(ZVEC *, int, int, ZVEC *, int);
  9974. -extern ZVEC    *zmv_move(ZMAT *, int, int, int, int, ZVEC *, int);
  9975. -extern complex    z_finput(FILE *fp);
  9976. -extern ZMAT    *zm_finput(FILE *fp,ZMAT *a);
  9977. -extern ZVEC     *zv_finput(FILE *fp,ZVEC *x);
  9978. -extern ZMAT    *zm_add(ZMAT *mat1,ZMAT *mat2,ZMAT *out);
  9979. -extern ZMAT    *zm_sub(ZMAT *mat1,ZMAT *mat2,ZMAT *out);
  9980. -extern ZMAT    *zm_mlt(ZMAT *A,ZMAT *B,ZMAT *OUT);
  9981. -extern ZMAT    *zmma_mlt(ZMAT *A,ZMAT *B,ZMAT *OUT);
  9982. -extern ZMAT    *zmam_mlt(ZMAT *A,ZMAT *B,ZMAT *OUT);
  9983. -extern ZVEC    *zmv_mlt(ZMAT *A,ZVEC *b,ZVEC *out);
  9984. -extern ZMAT    *zsm_mlt(complex scalar,ZMAT *matrix,ZMAT *out);
  9985. -extern ZVEC    *zvm_mlt(ZMAT *A,ZVEC *b,ZVEC *out);
  9986. -extern ZMAT    *zm_adjoint(ZMAT *in,ZMAT *out);
  9987. -extern ZMAT    *zswap_rows(ZMAT *A,int i,int j,int lo,int hi);
  9988. -extern ZMAT    *zswap_cols(ZMAT *A,int i,int j,int lo,int hi);
  9989. -extern ZMAT    *mz_mltadd(ZMAT *A1,ZMAT *A2,complex s,ZMAT *out);
  9990. -extern ZVEC    *zmv_mltadd(ZVEC *v1,ZVEC *v2,ZMAT *A,complex alpha,ZVEC *out);
  9991. -extern ZVEC    *zvm_mltadd(ZVEC *v1,ZVEC *v2,ZMAT *A,complex alpha,ZVEC *out);
  9992. -extern ZVEC    *zv_zero(ZVEC *x);
  9993. -extern ZMAT    *zm_zero(ZMAT *A);
  9994. -extern ZMAT    *zm_get(int m,int n);
  9995. -extern ZVEC    *zv_get(int dim);
  9996. -extern ZMAT    *zm_resize(ZMAT *A,int new_m,int new_n);
  9997. -extern complex    _zin_prod(ZVEC *x,ZVEC *y,u_int i0,u_int flag);
  9998. -extern ZVEC    *zv_resize(ZVEC *x,int new_dim);
  9999. -extern ZVEC    *zv_mlt(complex scalar,ZVEC *vector,ZVEC *out);
  10000. -extern ZVEC    *zv_add(ZVEC *vec1,ZVEC *vec2,ZVEC *out);
  10001. -extern ZVEC    *zv_mltadd(ZVEC *v1,ZVEC *v2,complex scale,ZVEC *out);
  10002. -extern ZVEC    *zv_sub(ZVEC *vec1,ZVEC *vec2,ZVEC *out);
  10003. -#ifdef PROTOTYPES_IN_STRUCT
  10004. -extern ZVEC    *zv_map(complex (*f)(),ZVEC *x,ZVEC *out);
  10005. -extern ZVEC    *_zv_map(complex (*f)(),void *params,ZVEC *x,ZVEC *out);
  10006. -#else
  10007. -extern ZVEC    *zv_map(complex (*f)(complex),ZVEC *x,ZVEC *out);
  10008. -extern ZVEC    *_zv_map(complex (*f)(void *,complex),void *params,ZVEC *x,ZVEC *out);
  10009. -#endif
  10010. -extern ZVEC    *zv_lincomb(int n,ZVEC *v[],complex a[],ZVEC *out);
  10011. -extern ZVEC    *zv_linlist(ZVEC *out,ZVEC *v1,complex a1,...);
  10012. -extern ZVEC    *zv_star(ZVEC *x1, ZVEC *x2, ZVEC *out);
  10013. -extern ZVEC    *zv_slash(ZVEC *x1, ZVEC *x2, ZVEC *out);
  10014. -extern int    zm_free(ZMAT *mat);
  10015. -extern int    zv_free(ZVEC *vec);
  10016. -
  10017. -extern ZVEC    *zv_rand(ZVEC *x);
  10018. -extern ZMAT    *zm_rand(ZMAT *A);
  10019. -
  10020. -extern ZVEC    *zget_row(ZMAT *A, int i, ZVEC *out);
  10021. -extern ZVEC    *zget_col(ZMAT *A, int j, ZVEC *out);
  10022. -extern ZMAT    *zset_row(ZMAT *A, int i, ZVEC *in);
  10023. -extern ZMAT    *zset_col(ZMAT *A, int j, ZVEC *in);
  10024. -
  10025. -extern ZVEC    *px_zvec(PERM *pi, ZVEC *in, ZVEC *out);
  10026. -extern ZVEC    *pxinv_zvec(PERM *pi, ZVEC *in, ZVEC *out);
  10027. -
  10028. -extern void    __zconj__(complex zp[], int len);
  10029. -extern complex    __zip__(complex zp1[],complex zp2[],int len,int flag);
  10030. -extern void    __zmltadd__(complex zp1[],complex zp2[],
  10031. -                complex s,int len,int flag);
  10032. -extern void    __zmlt__(complex zp[],complex s,complex out[],int len);
  10033. -extern void    __zadd__(complex zp1[],complex zp2[],complex out[],int len);
  10034. -extern void    __zsub__(complex zp1[],complex zp2[],complex out[],int len);
  10035. -extern void    __zzero__(complex zp[],int len);
  10036. -extern void    z_foutput(FILE *fp,complex z);
  10037. -extern void     zm_foutput(FILE *fp,ZMAT *a);
  10038. -extern void     zv_foutput(FILE *fp,ZVEC *x);
  10039. -extern void     zm_dump(FILE *fp,ZMAT *a);
  10040. -extern void     zv_dump(FILE *fp,ZVEC *x);
  10041. -
  10042. -extern double    _zv_norm1(ZVEC *x, VEC *scale);
  10043. -extern double    _zv_norm2(ZVEC *x, VEC *scale);
  10044. -extern double    _zv_norm_inf(ZVEC *x, VEC *scale);
  10045. -extern double    zm_norm1(ZMAT *A);
  10046. -extern double    zm_norm_inf(ZMAT *A);
  10047. -extern double    zm_norm_frob(ZMAT *A);
  10048. -
  10049. -complex    zmake(double real, double imag);
  10050. -double    zabs(complex z);
  10051. -complex zadd(complex z1,complex z2);
  10052. -complex zsub(complex z1,complex z2);
  10053. -complex    zmlt(complex z1,complex z2);
  10054. -complex    zinv(complex z);
  10055. -complex    zdiv(complex z1,complex z2);
  10056. -complex    zsqrt(complex z);
  10057. -complex    zexp(complex z);
  10058. -complex    zlog(complex z);
  10059. -complex    zconj(complex z);
  10060. -complex    zneg(complex z);
  10061. -#else
  10062. -extern ZMAT    *_zm_copy();
  10063. -extern ZVEC    *_zv_copy();
  10064. -extern ZMAT    *zm_finput();
  10065. -extern ZVEC     *zv_finput();
  10066. -extern ZMAT    *zm_add();
  10067. -extern ZMAT    *zm_sub();
  10068. -extern ZMAT    *zm_mlt();
  10069. -extern ZMAT    *zmma_mlt();
  10070. -extern ZMAT    *zmam_mlt();
  10071. -extern ZVEC    *zmv_mlt();
  10072. -extern ZMAT    *zsm_mlt();
  10073. -extern ZVEC    *zvm_mlt();
  10074. -extern ZMAT    *zm_adjoint();
  10075. -extern ZMAT    *zswap_rows();
  10076. -extern ZMAT    *zswap_cols();
  10077. -extern ZMAT    *mz_mltadd();
  10078. -extern ZVEC    *zmv_mltadd();
  10079. -extern ZVEC    *zvm_mltadd();
  10080. -extern ZVEC    *zv_zero();
  10081. -extern ZMAT    *zm_zero();
  10082. -extern ZMAT    *zm_get();
  10083. -extern ZVEC    *zv_get();
  10084. -extern ZMAT    *zm_resize();
  10085. -extern ZVEC    *zv_resize();
  10086. -extern complex    _zin_prod();
  10087. -extern ZVEC    *zv_mlt();
  10088. -extern ZVEC    *zv_add();
  10089. -extern ZVEC    *zv_mltadd();
  10090. -extern ZVEC    *zv_sub();
  10091. -extern ZVEC    *zv_map();
  10092. -extern ZVEC    *_zv_map();
  10093. -extern ZVEC    *zv_lincomb();
  10094. -extern ZVEC    *zv_linlist();
  10095. -extern ZVEC    *zv_star();
  10096. -extern ZVEC    *zv_slash();
  10097. -
  10098. -extern ZVEC    *px_zvec();
  10099. -extern ZVEC    *pxinv_zvec();
  10100. -
  10101. -extern ZVEC    *zv_rand();
  10102. -extern ZMAT    *zm_rand();
  10103. -
  10104. -extern ZVEC    *zget_row();
  10105. -extern ZVEC    *zget_col();
  10106. -extern ZMAT    *zset_row();
  10107. -extern ZMAT    *zset_col();
  10108. -
  10109. -extern int    zm_free();
  10110. -extern int    zv_free();
  10111. -extern void    __zconj__();
  10112. -extern complex    __zip__();
  10113. -extern void    __zmltadd__();
  10114. -extern void    __zmlt__();
  10115. -extern void    __zadd__();
  10116. -extern void    __zsub__();
  10117. -extern void    __zzero__();
  10118. -extern void    zm_foutput();
  10119. -extern void    zv_foutput();
  10120. -extern void    zm_dump();
  10121. -extern void    zv_dump();
  10122. -
  10123. -extern double    _zv_norm1();
  10124. -extern double    _zv_norm2();
  10125. -extern double    _zv_norm_inf();
  10126. -extern double    zm_norm1();
  10127. -extern double    zm_norm_inf();
  10128. -extern double    zm_norm_frob();
  10129. -
  10130. -complex    zmake();
  10131. -double    zabs();
  10132. -complex zadd();
  10133. -complex zsub();
  10134. -complex    zmlt();
  10135. -complex    zinv();
  10136. -complex    zdiv();
  10137. -complex    zsqrt();
  10138. -complex    zexp();
  10139. -complex    zlog();
  10140. -complex    zconj();
  10141. -complex    zneg();
  10142. -#endif
  10143. -
  10144. -#define    zv_copy(x,y)    _zv_copy(x,y,0)
  10145. -#define    zm_copy(A,B)    _zm_copy(A,B,0,0)
  10146. -
  10147. -#define    z_input()    z_finput(stdin)
  10148. -#define    zv_input(x)    zv_finput(stdin,x)
  10149. -#define    zm_input(A)    zm_finput(stdin,A)
  10150. -#define    z_output(z)    z_foutput(stdout,z)
  10151. -#define    zv_output(x)    zv_foutput(stdout,x)
  10152. -#define    zm_output(A)    zm_foutput(stdout,A)
  10153. -
  10154. -#define    ZV_FREE(x)    ( zv_free(x), (x) = ZVNULL )
  10155. -#define    ZM_FREE(A)    ( zm_free(A), (A) = ZMNULL )
  10156. -
  10157. -#define    zin_prod(x,y)    _zin_prod(x,y,0,Z_CONJ)
  10158. -
  10159. -#define    zv_norm1(x)    _zv_norm1(x,VNULL)
  10160. -#define    zv_norm2(x)    _zv_norm2(x,VNULL)
  10161. -#define    zv_norm_inf(x)    _zv_norm_inf(x,VNULL)
  10162. -
  10163. -
  10164. -#endif
  10165. //GO.SYSIN DD zmatrix.h
  10166. echo zmatrix2.h 1>&2
  10167. sed >zmatrix2.h <<'//GO.SYSIN DD zmatrix2.h' 's/^-//'
  10168. -
  10169. -/**************************************************************************
  10170. -**
  10171. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  10172. -**
  10173. -**                 Meschach Library
  10174. -** 
  10175. -** This Meschach Library is provided "as is" without any express 
  10176. -** or implied warranty of any kind with respect to this software. 
  10177. -** In particular the authors shall not be liable for any direct, 
  10178. -** indirect, special, incidental or consequential damages arising 
  10179. -** in any way from use of the software.
  10180. -** 
  10181. -** Everyone is granted permission to copy, modify and redistribute this
  10182. -** Meschach Library, provided:
  10183. -**  1.  All copies contain this copyright notice.
  10184. -**  2.  All modified copies shall carry a notice stating who
  10185. -**      made the last modification and the date of such modification.
  10186. -**  3.  No charge is made for this software or works derived from it.  
  10187. -**      This clause shall not be construed as constraining other software
  10188. -**      distributed on the same medium as this software, nor is a
  10189. -**      distribution fee considered a charge.
  10190. -**
  10191. -***************************************************************************/
  10192. -
  10193. -
  10194. -/*
  10195. -    2nd header file for Meschach's complex routines.
  10196. -    This file contains declarations for complex factorisation/solve
  10197. -    routines.
  10198. -
  10199. -*/
  10200. -
  10201. -
  10202. -#ifndef ZMATRIX2H
  10203. -#define ZMATRIX2H
  10204. -
  10205. -#include "zmatrix.h"
  10206. -
  10207. -#ifdef ANSI_C
  10208. -extern ZVEC    *zUsolve(ZMAT *matrix, ZVEC *b, ZVEC *out, double diag);
  10209. -extern ZVEC    *zLsolve(ZMAT *matrix, ZVEC *b, ZVEC *out, double diag);
  10210. -extern ZVEC    *zUAsolve(ZMAT *U, ZVEC *b, ZVEC *out, double diag);
  10211. -extern ZVEC    *zDsolve(ZMAT *A, ZVEC *b, ZVEC *x);
  10212. -extern ZVEC    *zLAsolve(ZMAT *L, ZVEC *b, ZVEC *out, double diag);
  10213. -
  10214. -extern ZVEC    *zhhvec(ZVEC *,int,Real *,ZVEC *,complex *);
  10215. -extern ZVEC    *zhhtrvec(ZVEC *,double,int,ZVEC *,ZVEC *);
  10216. -extern ZMAT    *zhhtrrows(ZMAT *,int,int,ZVEC *,double);
  10217. -extern ZMAT    *zhhtrcols(ZMAT *,int,int,ZVEC *,double);
  10218. -extern ZMAT     *zHfactor(ZMAT *,ZVEC *);
  10219. -extern ZMAT     *zHQunpack(ZMAT *,ZVEC *,ZMAT *,ZMAT *);
  10220. -
  10221. -extern ZMAT    *zQRfactor(ZMAT *A, ZVEC *diag);
  10222. -extern ZMAT    *zQRCPfactor(ZMAT *A, ZVEC *diag, PERM *px);
  10223. -extern ZVEC    *_zQsolve(ZMAT *QR, ZVEC *diag, ZVEC *b, ZVEC *x, ZVEC *tmp);
  10224. -extern ZMAT    *zmakeQ(ZMAT *QR, ZVEC *diag, ZMAT *Qout);
  10225. -extern ZMAT    *zmakeR(ZMAT *QR, ZMAT *Rout);
  10226. -extern ZVEC    *zQRsolve(ZMAT *QR, ZVEC *diag, ZVEC *b, ZVEC *x);
  10227. -extern ZVEC    *zQRAsolve(ZMAT *QR, ZVEC *diag, ZVEC *b, ZVEC *x);
  10228. -extern ZVEC    *zQRCPsolve(ZMAT *QR,ZVEC *diag,PERM *pivot,ZVEC *b,ZVEC *x);
  10229. -extern ZVEC    *zUmlt(ZMAT *U, ZVEC *x, ZVEC *out);
  10230. -extern ZVEC    *zUAmlt(ZMAT *U, ZVEC *x, ZVEC *out);
  10231. -extern double    zQRcondest(ZMAT *QR);
  10232. -
  10233. -extern ZVEC    *zLsolve(ZMAT *, ZVEC *, ZVEC *, double);
  10234. -extern ZMAT    *zset_col(ZMAT *, int, ZVEC *);
  10235. -
  10236. -extern ZMAT    *zLUfactor(ZMAT *A, PERM *pivot);
  10237. -extern ZVEC    *zLUsolve(ZMAT *A, PERM *pivot, ZVEC *b, ZVEC *x);
  10238. -extern ZVEC    *zLUAsolve(ZMAT *LU, PERM *pivot, ZVEC *b, ZVEC *x);
  10239. -extern ZMAT    *zm_inverse(ZMAT *A, ZMAT *out);
  10240. -extern double    zLUcondest(ZMAT *LU, PERM *pivot);
  10241. -
  10242. -extern void    zgivens(complex, complex, Real *, complex *);
  10243. -extern ZMAT    *zrot_rows(ZMAT *A, int i, int k, double c, complex s,
  10244. -               ZMAT *out);
  10245. -extern ZMAT    *zrot_cols(ZMAT *A, int i, int k, double c, complex s,
  10246. -               ZMAT *out);
  10247. -extern ZVEC    *rot_zvec(ZVEC *x, int i, int k, double c, complex s,
  10248. -              ZVEC *out);
  10249. -extern ZMAT    *zschur(ZMAT *A,ZMAT *Q);
  10250. -/* extern ZMAT    *schur_vecs(ZMAT *T,ZMAT *Q,X_re,X_im) */
  10251. -#else
  10252. -extern ZVEC    *zUsolve(), *zLsolve(), *zUAsolve(), *zDsolve(), *zLAsolve();
  10253. -
  10254. -extern ZVEC    *zhhvec();
  10255. -extern ZVEC    *zhhtrvec();
  10256. -extern ZMAT    *zhhtrrows();
  10257. -extern ZMAT     *zhhtrcols();
  10258. -extern ZMAT     *zHfactor();
  10259. -extern ZMAT     *zHQunpack();
  10260. -
  10261. -
  10262. -extern ZMAT    *zQRfactor(), *zQRCPfactor();
  10263. -extern ZVEC    *_zQsolve();
  10264. -extern ZMAT    *zmakeQ(), *zmakeR();
  10265. -extern ZVEC    *zQRsolve(), *zQRAsolve(), *zQRCPsolve();
  10266. -extern ZVEC    *zUmlt(), *zUAmlt();
  10267. -extern double    zQRcondest();
  10268. -
  10269. -extern ZVEC    *zLsolve();
  10270. -extern ZMAT    *zset_col();
  10271. -
  10272. -extern ZMAT    *zLUfactor();
  10273. -extern ZVEC    *zLUsolve(), *zLUAsolve();
  10274. -extern ZMAT    *zm_inverse();
  10275. -extern double    zLUcondest();
  10276. -
  10277. -extern void    zgivens();
  10278. -extern ZMAT    *zrot_rows(), *zrot_cols();
  10279. -extern ZVEC    *rot_zvec();
  10280. -extern ZMAT    *zschur();
  10281. -/* extern ZMAT    *schur_vecs(); */
  10282. -#endif
  10283. -
  10284. -#endif
  10285. -
  10286. //GO.SYSIN DD zmatrix2.h
  10287. mkdir DOC
  10288. echo DOC/fnindex.txt 1>&2
  10289. sed >DOC/fnindex.txt <<'//GO.SYSIN DD DOC/fnindex.txt' 's/^-//'
  10290. -
  10291. -                  FUNCTION INDEX
  10292. -                  ==============
  10293. -
  10294. -In the descriptions below, matrices are represented by capital letters,
  10295. -vectors by lower case letters and scalars by alpha.
  10296. -
  10297. - Function    Description
  10298. -
  10299. -band2mat()    Convert band matrix to dense matrix
  10300. -bd_free()    Deallocate (destroy) band matrix
  10301. -bd_get()    Allocate and initialise band matrix
  10302. -bd_transp()    Transpose band matrix
  10303. -bd_resize()    Resize band matrix
  10304. -bdLDLfactor()    Band  LDL^T  factorisation
  10305. -bdLDLsolve()    Solve  Ax=b  using band  LDL^T  factors
  10306. -bdLUfactor()    Band  LU  factorisation
  10307. -bdLUsolve()    Solve  Ax=b  using band  LU  factors
  10308. -bisvd()        SVD of bi-diagonal matrix
  10309. -BKPfactor()    Bunch-Kaufman-Parlett factorisation
  10310. -BKPsolve()    Bunch-Kaufman-Parlett solver
  10311. -catch()        Catch a raised error (macro)
  10312. -catchall()    Catch any raised error (macro)
  10313. -catch_FPE()    Catch floating point error (sets flag)
  10314. -CHfactor()    Dense Cholesky factorisation
  10315. -CHsolve()    Cholesky solver
  10316. -d_save()    Save real in MATLAB format
  10317. -Dsolve()    Solve  Dx=y ,  D  diagonal
  10318. -ERRABORT()    Abort on error (sets flag, macro)
  10319. -ERREXIT()    Exit on error (sets flag, macro)
  10320. -error()        Raise an error (macro, see  ev_err())
  10321. -err_list_attach()     Attach new list of errors
  10322. -err_list_free()             Discard list of errors
  10323. -err_is_list_attached()     Checks for an error list
  10324. -ev_err()    Raise an error (function)
  10325. -fft()        Computes Fast Fourier Transform
  10326. -finput()    Input a simple data item from a stream
  10327. -fprompter()    Print prompt to  stderr
  10328. -get_col()    Extract a column from a matrix
  10329. -get_row()    Extract a row from a matrix
  10330. -givens()    Compute Givens parameters
  10331. -hhtrcols()    Compute  AP^T  where  P  is a Householder matrix
  10332. -hhtrrows()    Compute  PA  where  P  is a Householder matrix
  10333. -hhtrvec()    Compute  Px  where  P  is a Householder matrix
  10334. -hhvec()        Compute parameters for a Householder matrix
  10335. -ifft()        Computes inverse FFT
  10336. -in_prod()    Inner product of vectors
  10337. -input()        Input a simple data item from  stdin (macro)
  10338. -iter_arnoldi()    Arnoldi iterative method
  10339. -iter_arnoldi_iref()    Arnoldi iterative method with refinement
  10340. -iter_ATx()    Set  A^T  in ITER structure
  10341. -iter_Ax()    Set  A  in ITER structure
  10342. -iter_Bx()    Set preconditioner in ITER structure
  10343. -iter_cg()    Conjugate gradients iterative method
  10344. -iter_cgne()     Conjugate gradients for normal equations
  10345. -iter_cgs()    CGS iterative method
  10346. -iter_copy()    Copy ITER data structures
  10347. -iter_copy2()    Shallow copy of ITER data structures
  10348. -iter_dump()    Dump ITER data structure to a stream
  10349. -iter_free()    Free (deallocate) ITER structure
  10350. -iter_get()    Allocate ITER structure
  10351. -iter_gmres()    GMRES iterative method
  10352. -iter_lanczos()    Lanczos iterative method
  10353. -iter_lanczos2()    Lanczos method with Cullum and Willoughby extensions
  10354. -iter_lsqr()    LSQR iterative method
  10355. -iter_mgcr()    MGCR iterative method
  10356. -iter_resize()    Resize vectors in an ITER data structure
  10357. -iter_spcg()    Sparse matrix CG method
  10358. -iter_spcgne()   Sparse matrix CG method for normal equations
  10359. -iter_spcgs()    Sparse matrix CGS method
  10360. -iter_spgmres()  Sparse matrix GMRES method
  10361. -iter_splsqr()    Sparse matrix LSQR method
  10362. -iter_spmgcr()    Sparse matrix MGCR method
  10363. -iv_add()    Add integer vectors
  10364. -iv_copy()    Copy integer vector
  10365. -iv_dump()    Dump integer vector to a stream
  10366. -iv_finput()    Input integer vector from a stream
  10367. -iv_foutput()    Output integer vector to a stream
  10368. -IV_FREE()    Free (deallocate) an integer vector (macro)
  10369. -iv_free()    Free (deallocate) integer vector (function)
  10370. -iv_free_vars()    Free a list of integer vectors
  10371. -iv_get()    Allocate and initialise an integer vector
  10372. -iv_get_vars()    Allocate list of integer vectors
  10373. -iv_input()    Input integer vector from  stdin (macro)
  10374. -iv_output()    Output integer vector to  stdout (macro)
  10375. -iv_resize()    Resize an integer vector
  10376. -iv_resize_vars()    Resize a list of integer vectors
  10377. -iv_sub()    Subtract integer vectors
  10378. -LDLfactor()    LDL^T  factorisation
  10379. -LDLsolve()    LDL^T  solver
  10380. -LDLupdate()    Update  LDL^T  factorisation
  10381. -Lsolve()    Solve  Lx=y ,  L  lower triangular
  10382. -LTsolve()    Solve  L^Tx=y ,  L  lower triangular
  10383. -LUcondest()    Estimate a condition number using  LU  factors
  10384. -LUfactor()    Compute  LU  factors with implicit scaled partial pivoting
  10385. -LUsolve()    Solve  Ax=b  using  LU  factors
  10386. -LUTsolve()    Solve  A^Tx=b  usng  LU  factors
  10387. -m_add()            Add matrices
  10388. -makeQ()            Form Q matrix for QR factorisation
  10389. -makeR()            Form R matrix for QR factorisation
  10390. -mat2band()    Extract band matrix from dense matrix
  10391. -MCHfactor()    Modified Cholesky factorisation 
  10392. -        (actually factors A+D, D diagonal, instead of A)
  10393. -m_copy()    Copy dense matrix
  10394. -m_dump()    Dump matrix data structure to a stream
  10395. -mem_attach_list()    Adds a new family of types
  10396. -mem_bytes()            Notify change in memory usage (macro)
  10397. -mem_bytes_list()    Notify change in memory usage
  10398. -mem_free_list()            Frees a family of types
  10399. -mem_info_bytes()    Number of bytes used by a type
  10400. -mem_info_numvar()    Number of structures of a type
  10401. -mem_info_file()            Print memory info to a stream
  10402. -mem_info_is_on()    Is memory data being accumulated?
  10403. -mem_info_on()            Turns memory info system on/off
  10404. -mem_is_list_attached()    Is list of types attached?
  10405. -mem_numvar()            Notify change in number of structures allocated (macro)
  10406. -mem_numvar_list()    Notify change in number of structures allocated
  10407. -mem_stat_dump()    Prints information on registered workspace
  10408. -mem_stat_free()    Frees (deallocates) static workspace
  10409. -mem_stat_mark()    Sets mark for workspace
  10410. -MEM_STAT_REG()    Register static workspace (macro)
  10411. -mem_stat_show_mark()    Current workspace group
  10412. -m_exp()        Computes matrix exponential
  10413. -m_finput()    Input matrix from a stream
  10414. -m_foutput()    Output matrix to a stream
  10415. -M_FREE()    Free (deallocate) a matrix (macro)
  10416. -m_free()    Free (deallocate) matrix (function)
  10417. -m_free_vars()    Free a list of matrices
  10418. -m_get()            Allocate and initialise a matrix
  10419. -m_get_vars()    Allocate list of matrices
  10420. -m_ident()    Sets matrix to identity matrix
  10421. -m_input()    Input matrix from  stdin (macro)
  10422. -m_inverse()    Invert matrix
  10423. -m_load()    Load matrix in MATLAB format
  10424. -m_mlt()            Multiplies matrices
  10425. -mmtr_mlt()    Computes  AB^T 
  10426. -m_norm1()    Computes  ||A||_1  of a matrix
  10427. -m_norm_frob()    Computes the Frobenius norm of a matrix
  10428. -m_norm_inf()    Computes  ||A||_inf  of a matrix
  10429. -m_ones()    Set matrix to all 1's
  10430. -m_output()    Output matrix to stdout (macro)
  10431. -m_poly()    Computes a matrix polynomial
  10432. -m_pow()        Computes integer power of a matrix
  10433. -mrand()        Generates pseudo-random real number
  10434. -m_rand()    Randomise entries of a matrix
  10435. -mrandlist()    Generates array of pseudo-random numbers
  10436. -m_resize()    Resize matrix
  10437. -m_resize_vars()    Resize a list of matrices
  10438. -m_save()    Save matrix in MATLAB format
  10439. -m_sub()        Subtract matrices
  10440. -m_transp()    Transpose matrix
  10441. -mtrm_mlt()    Computes  A^TB 
  10442. -mv_mlt()    Computes  Ax 
  10443. -mv_mltadd()    Computes  y <- Ax+y 
  10444. -m_zero()    Zero a matrix
  10445. -ON_ERROR()    Error handler (macro)
  10446. -prompter()    Print prompt message to  stdout
  10447. -px_cols()    Permute the columns of a matrix
  10448. -px_copy()    Copy permutation
  10449. -px_dump()    Dump permutation data structure to a stream
  10450. -px_finput()    Input permutation from a stream
  10451. -px_foutput()    Output permutation to a stream
  10452. -PX_FREE()    Free (deallocate) a permutation (macro)
  10453. -px_free()    Free (deallocate) permutation (function)
  10454. -px_free_vars()    Free a list of permutations
  10455. -px_get()    Allocate and initialise a permutation
  10456. -px_get_vars()    Allocate a list of permutations
  10457. -px_ident()    Sets permutation to identity
  10458. -px_input()    Input permutation from  stdin (macro)
  10459. -px_inv()    Invert permutation
  10460. -pxinv_vec()    Computes  P^Tx  where  P  is a permutation matrix
  10461. -pxinv_zvec()    Computes  P^Tx  where  P  is a permutation matrix (complex)
  10462. -px_mlt()    Multiply permutations
  10463. -px_output()    Output permutation to  stdout (macro)
  10464. -px_resize()    Resize a permutation
  10465. -px_resize_vars()    Resize a list of permutations
  10466. -px_rows()    Permute the rows of a matrix
  10467. -px_sign()    Returns the sign of the permutation
  10468. -px_transp()    Transpose a pair of entries
  10469. -px_vec()    Computes  Px  where  P  is a permutation matrix
  10470. -px_zvec()    Computes  Px  where  P  is a permutation matrix (complex)
  10471. -QRCPfactor()    QR factorisation with column pivoting
  10472. -QRfactor()    QR factorisation
  10473. -QRsolve()    Solve  Ax=b  using  QR  factorisation
  10474. -QRTsolve()    Solve  A^Tx=b  using  QR  factorisation
  10475. -QRupdate()    Update explicit  QR  factors
  10476. -rot_cols()    Apply Givens rotation to the columns of a matrix
  10477. -rot_rows()    Apply Givens rotation to the rows of a matrix
  10478. -rot_vec()    Apply Givens rotation to a vector
  10479. -rot_zvec()    Apply complex Givens rotation to a vector
  10480. -schur()        Compute real Schur form
  10481. -schur_evals()    Compute eigenvalues from the real Schur form
  10482. -schur_vecs()    Compute eigenvectors from the real Schur form
  10483. -set_col()    Set the column of a matrix to a given vector
  10484. -set_err_flag()    Control behaviour of  ev_err()
  10485. -set_row()    Set the row of a matrix to a given vector
  10486. -sm_mlt()    Scalar-matrix multiplication
  10487. -smrand()    Set seed for mrand()
  10488. -spBKPfactor()    Sparse symmetric indefinite factorsiation
  10489. -spBKPsolve()    Sparse symmetric indefinite solver
  10490. -spCHfactor()    Sparse Cholesky factorisation
  10491. -spCHsolve()    Sparse Cholesky solver
  10492. -spCHsymb()    Symbolic sparse Cholesky factorisation 
  10493. -        (no floating point operations)
  10494. -sp_col_access()    Sets up column access paths for a sparse matrix
  10495. -sp_compact()    Eliminates zero entries in a sparse matrix
  10496. -sp_copy()    Copies a sparse matrix
  10497. -sp_copy2()    Copies a sparse matrix into another
  10498. -sp_diag_access()    Sets up diagonal access paths for a sparse matrix
  10499. -sp_dump()    Dump sparse matrix data structure to a stream
  10500. -sp_finput()    Input sparse matrix from a stream
  10501. -sp_foutput()    Output a sparse matrix to a stream
  10502. -sp_free()    Free (deallocate) a sparse matrix
  10503. -sp_get()    Allocate and initialise a sparse matrix
  10504. -sp_get_val()    Get the  (i,j)  entry of a sparse matrix
  10505. -spICHfactor()    Sparse incomplete Cholesky factorisation
  10506. -sp_input()    Input a sparse matrix form  stdin
  10507. -spLUfactor()    Sparse  LU  factorisation using partial pivoting
  10508. -spLUsolve()    Solves  Ax=b  using sparse  LU  factors
  10509. -spLUTsolve()    Solves  A^Tx=b  using sparse  LU  factors
  10510. -sp_mv_mlt()    Computes  Ax  for sparse  A 
  10511. -sp_output()    Outputs a sparse matrix to a stream (macro)
  10512. -sp_resize()    Resize a sparse matrix
  10513. -sprow_add()    Adds a pair of sparse rows
  10514. -sprow_foutput()    Output sparse row to a stream
  10515. -sprow_get()    Allocate and initialise a sparse row
  10516. -sprow_get_idx()    Get location of an entry in a sparse row
  10517. -sprow_merge()    Merge two sparse rows
  10518. -sprow_mltadd()    Sparse row vector multiply-and-add
  10519. -sprow_set_val()    Set an entry in a sparse row
  10520. -sprow_smlt()    Multiplies a sparse row by a scalar
  10521. -sprow_sub()    Subtracts a sparse row from another
  10522. -sprow_xpd()    Expand a sparse row
  10523. -sp_set_val()    Set the  (i,j)  entry of a sparse matrix
  10524. -sp_vm_mlt()    Compute  x^TA  for sparse  A 
  10525. -sp_zero()    Zero (but do not remove) all entries of a sparse matrix
  10526. -svd()        Compute the SVD of a matrix
  10527. -sv_mlt()    Scalar-vector multiply
  10528. -symmeig()    Compute eigenvalues/vectors of a symmetric matrix
  10529. -tracecatch()    Catch and re-raise errors (macro)
  10530. -trieig()    Compute eigenvalues/vectors of a symmetric tridiagonal matrix
  10531. -Usolve()    Solve  Ux=b  where  U  is upper triangular
  10532. -UTsolve()    Solve  U^Tx=b  where  U  is upper triangular
  10533. -v_add()        Add vectors
  10534. -v_conv()    Convolution product of vectors
  10535. -v_copy()    Copy vector
  10536. -v_dump()    Dump vector data structure to a stream
  10537. -v_finput()    Input vector from a stream
  10538. -v_foutput()    Output vector to a stream
  10539. -V_FREE()    Free (deallocate) a vector (macro)
  10540. -v_free()    Free (deallocate) vector (function)
  10541. -v_free_vars()    Free a list of vectors
  10542. -v_get()        Allocate and initialise a vector
  10543. -v_get_vars()    Allocate list of vectors
  10544. -v_input()    Input vector from  stdin (macro)
  10545. -v_lincomb()    Compute  sum of a_i x_i  for an array of vectors
  10546. -v_linlist()    Compute  sum of a_i x_i  for a list of vectors
  10547. -v_map()        Apply function componentwise to a vector
  10548. -v_max()        Computes max vector entry and index
  10549. -v_min()        Computes min vector entry and index
  10550. -v_mltadd()    Computes  y <- alpha*x+y  for vectors  x ,  y 
  10551. -vm_mlt()    Computes  x^TA 
  10552. -vm_mltadd()    Computes  y^T <- y^T+x^TA 
  10553. -v_norm1()    Computes  ||x||_1  for a vector
  10554. -v_norm2()    Computes  ||x||_2  (the Euclidean norm) of a vector
  10555. -v_norm_inf()    Computes  ||x||_inf  for a vector
  10556. -v_ones()    Set vector to all 1's
  10557. -v_output()    Output vector to  stdout (macro)
  10558. -v_pconv()    Periodic convolution of two vectors
  10559. -v_rand()    Randomise entries of a vector
  10560. -v_resize()    Resize a vector
  10561. -v_resize_vars()    Resize a list of vectors
  10562. -v_save()    Save a vector in MATLAB format
  10563. -v_slash()    Computes componentwise ratio of vectors
  10564. -v_sort()    Sorts vector components
  10565. -v_star()    Componentwise vector product
  10566. -v_sub()        Subtract two vectors
  10567. -v_sum()        Sum of components of a vector
  10568. -v_zero()    Zero a vector
  10569. -zabs()        Complex absolute value (modulus)
  10570. -zadd()        Add complex numbers
  10571. -zconj()        Conjugate complex number
  10572. -zdiv()        Divide complex numbers
  10573. -zexp()        Complex exponential
  10574. -z_finput()    Read complex number from file or stream
  10575. -z_foutput()    Prints complex number to file or stream
  10576. -zgivens()    Compute complex Givens' rotation
  10577. -zhhtrcols()    Apply Householder transformation:  PA  (complex)
  10578. -zhhtrrows()    Apply Householder transformation:  AP  (complex)
  10579. -zhhtrvec()    Apply Householder transformation:  Px  (complex)
  10580. -zhhvec()    Compute Householder transformation
  10581. -zin_prod()    Complex inner product
  10582. -z_input()    Read complex number from stdin
  10583. -zinv()        Computes  1/z  (complex)
  10584. -zLAsolve()    Solve  L^*x=b ,  L  complex lower triangular
  10585. -zlog()        Complex logarithm
  10586. -zLsolve()    Solve  Lx=b ,  L  complex lower triangular
  10587. -zLUAsolve()    Solve  A^*x=b  using complex LU factorisation 
  10588. -        (A^* - adjoint of A, A is complex)
  10589. -zLUcondest()    Complex LU condition estimate
  10590. -zLUfactor()    Complex LU factorisation
  10591. -zLUsolve()    Solve  Ax=b  using complex LU factorisation
  10592. -zm_add()    Add complex matrices
  10593. -zm_adjoint()    Computes adjoint of complex matrix
  10594. -zmake()        Construct complex number from real and imaginary parts
  10595. -zmakeQ()    Construct  Q  matrix for complex  QR 
  10596. -zmakeR()    Construct  R  matrix for complex  QR 
  10597. -zmam_mlt()    Computes  A^*B  (complex)
  10598. -zm_dump()    Dump complex matrix to stream
  10599. -zm_finput()    Input complex matrix from stream
  10600. -ZM_FREE()    Free (deallocate) complex matrix (macro)
  10601. -zm_free()    Free (deallocate) complex matrix (function)
  10602. -zm_free_vars()    Free a list of complex matrices
  10603. -zm_get()    Allocate complex matrix
  10604. -zm_get_vars()    Allocate a list of complex matrices
  10605. -zm_input()    Input complex matrix from stdin
  10606. -zm_inverse()    Compute inverse of complex matrix
  10607. -zm_load()    Load complex matrix in MATLAB format
  10608. -zmlt()        Multiply complex numbers
  10609. -zmma_mlt()    Computes  AB^*  (complex)
  10610. -zm_mlt()    Multiply complex matrices
  10611. -zm_norm1()    Complex matrix 1-norm
  10612. -zm_norm_frob()    Complex matrix Frobenius norm
  10613. -zm_norm_inf()    Complex matrix infinity-norm
  10614. -zm_rand()    Randomise complex matrix
  10615. -zm_resize()    Resize complex matrix
  10616. -zm_resize_vars()    Resize a list of complex matrices
  10617. -zm_save()    Save complex matrix in MATLAB format
  10618. -zm_sub()    Subtract complex matrices
  10619. -zmv_mlt()    Complex matrix-vector multiply
  10620. -zmv_mltadd()    Complex matrix-vector multiply and add
  10621. -zm_zero()    Zero complex matrix
  10622. -zneg()        Computes  -z  (complex)
  10623. -z_output()    Print complex number to stdout
  10624. -zQRCPfactor()    Complex  QR  factorisation with column pivoting
  10625. -zQRCPsolve()    Solve  Ax = b  using complex  QR  factorisation
  10626. -zQRfactor()    Complex  QR  factorisation
  10627. -zQRAsolve()    Solve  A^*x = b  using complex  QR  factorisation
  10628. -zQRsolve()    Solve  Ax = b  using complex  QR  factorisation
  10629. -zrot_cols()    Complex Givens' rotation of columns
  10630. -zrot_rows()    Complex Givens' rotation of rows
  10631. -z_save()    Save complex number in MATLAB format
  10632. -zschur()    Complex Schur factorisation
  10633. -zset_col()    Set column of complex matrix
  10634. -zset_row()    Set row of complex matrix
  10635. -zsm_mlt()    Complex scalar-matrix product
  10636. -zsqrt()        Square root  z  (complex)
  10637. -zsub()        Subtract complex numbers
  10638. -zUAsolve()    Solve  U^*x=b ,  U  complex upper triangular
  10639. -zUsolve()    Solve  Ux=b ,  U  complex upper triangular
  10640. -zv_add()    Add complex vectors
  10641. -zv_copy()    Copy complex vector
  10642. -zv_dump()    Dump complex vector to a stream
  10643. -zv_finput()    Input complex vector from a stream
  10644. -ZV_FREE()    Free (deallocate) complex vector (macro)
  10645. -zv_free()    Free (deallocate) complex vector (function)
  10646. -zv_free_vars()    Free a list of complex vectors
  10647. -zv_get()    Allocate complex vector
  10648. -zv_get_vars()    Allocate a list of complex vectors
  10649. -zv_input()    Input complex vector from a stdin
  10650. -zv_lincomb()    Compute  sum of a_i x_i  for an array of vectors
  10651. -zv_linlist()    Compute  sum of a_i x_i  for a list of vectors
  10652. -zv_map()    Apply function componentwise to a complex vector
  10653. -zv_mlt()    Complex scalar-vector product
  10654. -zv_mltadd()    Complex scalar-vector multiply and add
  10655. -zvm_mlt()    Computes  A^*x  (complex)
  10656. -zvm_mltadd()    Computes  A^*x+y  (complex)
  10657. -zv_norm1()    Complex vector 1-norm    vnorm1()
  10658. -zv_norm2()    Complex vector 2-norm  (Euclidean norm)
  10659. -zv_norm_inf()    Complex vector infinity- (or supremum) norm
  10660. -zv_rand()    Randomise complex vector
  10661. -zv_resize()    Resize complex vector
  10662. -zv_resize_vars()    Resize a list of complex vectors
  10663. -zv_save()    Save complex vector in MATLAB format
  10664. -zv_slash()    Componentwise ratio of complex vectors
  10665. -zv_star()    Componentwise product of complex vectors
  10666. -zv_sub()    Subtract complex vectors
  10667. -zv_sum()    Sum of components of a complex vector
  10668. -zv_zero()    Zero complex vector
  10669. -
  10670. -
  10671. -
  10672. -                Low level routines
  10673. -
  10674. -
  10675. - Function    Description
  10676. -
  10677. -__add__()    Add arrays
  10678. -__ip__()    Inner product of arrays
  10679. -MEM_COPY()    Copy memory (macro)
  10680. -MEM_ZERO()    Zero memory (macro)
  10681. -__mltadd__()    Forms  x+ alpha*y  for arrays
  10682. -__smlt__()    Scalar-vector multiplication for arrays
  10683. -__sub__()    Subtract an array from another
  10684. -__zadd__()    Add complex arrays
  10685. -__zconj__()    Conjugate complex array
  10686. -__zero__()    Zero an array
  10687. -__zip__()    Complex inner product of arrays
  10688. -__zmlt__()    Complex array scalar product
  10689. -__zmltadd__()    Complex array saxpy
  10690. -__zsub__()    Subtract complex arrays
  10691. -__zzero__()    Zero a complex array
  10692. -
  10693. -
  10694. //GO.SYSIN DD DOC/fnindex.txt
  10695. echo DOC/tutorial.txt 1>&2
  10696. sed >DOC/tutorial.txt <<'//GO.SYSIN DD DOC/tutorial.txt' 's/^-//'
  10697. -
  10698. -
  10699. -               MESCHACH VERSION 1.2A
  10700. -               ---------------------
  10701. -
  10702. -
  10703. -                 TUTORIAL
  10704. -                 ========
  10705. -
  10706. -
  10707. -   In this manual the basic data structures are introduced, and some of the
  10708. -more basic operations are illustrated.  Then some examples of how to use
  10709. -the data structures and procedures to solve some simple problems are given.
  10710. -The first example program is a simple 4th order Runge-Kutta solver for
  10711. -ordinary differential equations.  The second is a general least squares
  10712. -equation solver for over-determined equations.  The third example
  10713. -illustrates how to solve a problem involving sparse matrices.  These
  10714. -examples illustrate the use of matrices, matrix factorisations and solving
  10715. -systems of linear equations.  The examples described in this manual are
  10716. -implemented in tutorial.c.
  10717. -
  10718. -   While the description of each aspect of the system is brief and far from
  10719. -comprehensive, the aim is to show the different aspects of how to set up
  10720. -programs and routines and how these work in practice, which includes I/O
  10721. -and error-handling issues.
  10722. -
  10723. -
  10724. -
  10725. -1.  THE DATA STRUCTURES AND SOME BASIC OPERATIONS
  10726. -
  10727. -   The three main data structures are those describing vectors, matrices
  10728. -and permutations.  These have been used to create data structures for
  10729. -simplex tableaus for linear programming, and used with data structures for
  10730. -sparse matrices etc.  To use the system reliably, you should always use
  10731. -pointers to these data structures and use library routines to do all the
  10732. -necessary initialisation.
  10733. -
  10734. -   In fact, for the operations that involve memory management (creation,
  10735. -destruction and resizing), it is essential that you use the routines
  10736. -provided.
  10737. -
  10738. -   For example, to create a matrix A of size 34 , a vector x of dimension
  10739. -10, and a permutation p of size 10, use the following code:
  10740. -
  10741. -
  10742. -  #include "matrix.h"
  10743. -  ..............
  10744. -  main()
  10745. -  {
  10746. -     MAT   *A;
  10747. -     VEC   *x;
  10748. -     PERM  *p;
  10749. -     ..........
  10750. -     A = m_get(3,4);
  10751. -     x = v_get(10);
  10752. -     p = px_get(10);
  10753. -     ..........
  10754. -  }
  10755. -
  10756. -
  10757. -   This initialises these data structures to have the given size.  The
  10758. -matrix A and the vector x are initially all zero, while p is initially the
  10759. -identity permutation.
  10760. -
  10761. -   They can be disposed of by calling M_FREE(A), V_FREE(x) and PX_FREE(p)
  10762. -respectively if you need to re-use the memory for something else.  The
  10763. -elements of each data structure can be accessed directly using the members
  10764. -(or fields) of the corresponding structures.  For example the (i,j)
  10765. -component of A is accessed by A->me[i][j], x_i by x->ve[i] and p_i by
  10766. -p->pe[i].
  10767. -
  10768. -   Their sizes are also directly accessible: A->m and A->n are the number
  10769. -of rows and columns of A respectively, x->dim is the dimension of x , and
  10770. -size of p is p->size.
  10771. -
  10772. -   Note that the indexes are zero relative just as they are in ordinary C,
  10773. -so that the index i in x->ve[i] can range from 0 to x->dim -1 .  Thus the
  10774. -total number of entries of a vector is exactly x->dim.
  10775. -
  10776. -   While this alone is sufficient to allow a programmer to do any desired
  10777. -operation with vectors and matrices it is neither convenient for the
  10778. -programmer, nor efficient use of the CPU.  A whole library has been
  10779. -implemented to reduce the burden on the programmer in implementing
  10780. -algorithms with vectors and matrices.  For instance, to copy a vector from
  10781. -x to y it is sufficient to write y = v_copy(x,VNULL).  The VNULL is the
  10782. -NULL vector, and usually tells the routine called to create a vector for
  10783. -output.
  10784. -
  10785. -   Thus, the v_copy function will create a vector which has the same size
  10786. -as x and all the components are equal to those of x.  If y has already
  10787. -been created then you can write y = v_copy(x,y); in general, writing
  10788. -``v_copy(x,y);'' is not enough!  If y is NULL, then it is created (to have
  10789. -the correct size, i.e. the same size as x), and if it is the wrong size,
  10790. -then it is resized to have the correct size (i.e. same size as x).  Note
  10791. -that for all the following functions, the output value is returned, even if
  10792. -you have a non-NULL value as the output argument.  This is the standard
  10793. -across the entire library.
  10794. -
  10795. -   Addition, subtraction and scalar multiples of vectors can be computed by
  10796. -calls to library routines: v_add(x,y,out), v_sub(x,y,out), sv_mlt(s,x,out)
  10797. -where x and y are input vectors (with data type VEC *), out is the output
  10798. -vector (same data type) and s is a double precision number (data type
  10799. -double).  There is also a special combination routine, which computes
  10800. -out=v_1+s,v_2 in a single routine: v_mltadd(v1,v2,s,out).  This is not only
  10801. -extremely useful, it is also more efficient than using the scalar-vector
  10802. -multiply and vector addition routines separately.
  10803. -
  10804. -   Inner products can be computed directly: in_prod(x,y) returns the inner
  10805. -product of x and y.  Note that extended precision evaluation is not
  10806. -guaranteed.  The standard installation options uses double precision
  10807. -operations throughout the library.
  10808. -
  10809. -   Equivalent operations can be performed on matrices: m_add(A,B,C) which
  10810. -returns C=A+B , and sm_mlt(s,A,C) which returns C=sA .  The data types of
  10811. -A, B and C are all MAT *, while that of s is type double as before.  The
  10812. -matrix NULL is called MNULL.
  10813. -
  10814. -   Multiplying matrices and vectors can be done by a single function call:
  10815. -mv_mlt(A,x,out) returns out=A*x while vm_mlt(A,x,out) returns out=A^T*x , or
  10816. -equivalently, out^T=x^T*A .  Note that there is no distinction between row
  10817. -and column vectors unlike certain interactive environments such as MATLAB
  10818. -or MATCALC.
  10819. -
  10820. -   Permutations are also an essential part of the package.  Vectors can be
  10821. -permuted by using px_vec(p,x,p_x), rows and columns of matrices can be
  10822. -permuted by using px_rows(p,A,p_A), px_cols(p,A,A_p), and permutations can
  10823. -be multiplied using px_mlt(p1,p2,p1_p2) and inverted using px_inv(p,p_inv).
  10824. -The NULL permutation is called PXNULL.
  10825. -
  10826. -   There are also utility routines to initialise or re-initialise these
  10827. -data structures: v_zero(x), m_zero(A), m_ident(A) (which sets A=I of the
  10828. -correct size), v_rand(x), m_rand(A) which sets the entries of x and A
  10829. -respectively to be randomly and uniformly selected between zero and one,
  10830. -and px_ident(p) which sets p to be an identity permutation.
  10831. -
  10832. -   Input and output are accomplished by library routines v_input(x),
  10833. -m_input(A), and px_input(p).  If a null object is passed to any of these
  10834. -input routines, all data will be obtained from the input file, which is
  10835. -stdin.  If input is taken from a keyboard then the user will be prompted
  10836. -for all the data items needed; if input is taken from a file, then the
  10837. -input will have to be of the same format as that produced by the output
  10838. -routines, which are: v_output(x), m_output(A) and px_output(p).  This
  10839. -output is both human and machine readable!
  10840. -
  10841. -   If you wish to send the data to a file other than the standard output
  10842. -device stdout, or receive input from a file or device other than the
  10843. -standard input device stdin, take the appropriate routine above, use the
  10844. -``foutpout'' suffix instead of just ``output'', and add a file pointer as
  10845. -the first argument.  For example, to send a matrix A to a file called
  10846. -``fred'', use the following:
  10847. -
  10848. -
  10849. -  #include   "matrix.h"
  10850. -  .............
  10851. -  main()
  10852. -  {
  10853. -     FILE  *fp;
  10854. -     MAT   *A;
  10855. -     .............
  10856. -     fp = fopen("fred","w");
  10857. -     m_foutput(fp,A);
  10858. -     .............
  10859. -  }
  10860. -
  10861. -
  10862. -   These input routines allow for the presence of comments in the data.  A
  10863. -comment in the input starts with a ``hash'' character ``#'', and continues
  10864. -to the end of the line.  For example, the following is valid input for a
  10865. -3-dimensional vector:
  10866. -
  10867. -  # The initial vector must not be zero
  10868. -  # x =
  10869. -  Vector: dim: 3
  10870. -  -7      0     3
  10871. -
  10872. -
  10873. -   For general input/output which conforms to this format, allowing
  10874. -comments in the input files, use the input() and finput() macros.  These
  10875. -are used to print out a prompt message if stdin is a terminal (or ``tty''
  10876. -in Unix jargon), and to skip over any comments if input is from a
  10877. -non-interactive device.  An example of the usage of these macros is:
  10878. -
  10879. -  input("Input number of steps: ","%d",&steps);
  10880. -  fp = stdin;
  10881. -  finput(fp,"Input number of steps: ","%d",&steps);
  10882. -  fp = fopen("fred","r");
  10883. -  finput(fp,"Input number of steps: ","%d",&steps);
  10884. -
  10885. -The "%d" is one of the format specifiers which are used in fscanf(); the
  10886. -last argument is the pointer to the variable (unless the variable is a
  10887. -string) just as for scanf() and fscanf().  The first two macro calls read
  10888. -input from stdin, the last from the file fred.  If, in the first two calls,
  10889. -stdin is a keyboard (a ``tty'' in Unix jargon) then the prompt string
  10890. -  "Input number of steps: " 
  10891. -is printed out on the terminal.
  10892. -
  10893. -
  10894. -   The second part of the library contains routines for various
  10895. -factorisation methods.  To use it put
  10896. -
  10897. -  #include   "matrix2.h"
  10898. -
  10899. -at the beginning of your program.  It contains factorisation and solution
  10900. -routines for LU, Cholesky and QR-factorisation methods, as well as update
  10901. -routines for Cholesky and QR factorisations.  Supporting these are a number
  10902. -of Householder transformation and Givens' rotation routines.  Also there is
  10903. -a routine for generating the Q matrix for a QR-factorisation, if it is
  10904. -needed explicitly, as it often is.
  10905. -There are routines for band factorisation and solution for LU and  LDL^T 
  10906. -factorisations.
  10907. -
  10908. -For using complex numbers, vectors and matrices include
  10909. -
  10910. -  #include   "zmatrix.h"
  10911. -
  10912. -for using the basic routines, and
  10913. -
  10914. -  #include   "zmatrix2.h"
  10915. -
  10916. -for the complex matrix factorisation routines.  The zmatrix2.h file
  10917. -includes matrix.h and zmatrix.h so you don't need these files included
  10918. -together.
  10919. -
  10920. -For using the sparse matrix routines in the library you need to put
  10921. -
  10922. -  #include   "sparse.h"
  10923. -
  10924. -or, if you use any sparse factorisation routines,
  10925. -
  10926. -  #include   "sparse2.h"
  10927. -
  10928. -at the beginning of your file.  The routines contained in the library
  10929. -include routines for creating, destroying, initialising and updating sparse
  10930. -matrices, and also routines for sparse matrix-dense vector multiplication,
  10931. -sparse LU factorisation and sparse Cholesky factorisation.
  10932. -
  10933. -For using the iterative routines you need to use
  10934. -
  10935. -  #include   "iter.h"
  10936. -
  10937. -This includes the sparse.h and matrix.h file.
  10938. -There are also routines for applying iterative methods such as
  10939. -pre-conditioned conjugate gradient methods to sparse matrices.
  10940. -
  10941. -   And if you use the standard maths library (sin(), cos(), tan(), exp(),
  10942. -log(), sqrt(), acos() etc.)  don't forget to include the standard
  10943. -mathematics header:
  10944. -
  10945. -  #include  <math.h>
  10946. -
  10947. -This file is  not  automatically included by any of the Meschach
  10948. -header files.
  10949. -
  10950. -
  10951. -
  10952. -2.  HOW TO MANAGE MEMORY
  10953. -
  10954. -   Unlike many other numerical libraries, Meschach allows you to allocate,
  10955. -deallocate and resize the vectors, matrices and permutations that you are
  10956. -using.  To gain maximum benefit from this it is sometimes necessary to
  10957. -think a little about where memory is allocated and deallocated.  There are
  10958. -two reasons for this.
  10959. -
  10960. -   Memory allocation, deallocation and resizing takes a significant amount
  10961. -of time compared with (say) vector operations, so it should not be done too
  10962. -frequently.  Allocating memory but not deallocating it means that it cannot
  10963. -be used by any other data structure.  Data structures that are no longer
  10964. -needed should be explicitly deallocated, or kept as static variables for
  10965. -later use.  Unlike other interpreted systems (such as Lisp) there is no
  10966. -implicit ``garbage collection'' of no-longer-used memory.
  10967. -
  10968. -   There are three main strategies that are recommended for deciding how to
  10969. -allocate, deallocate and resize objects.  These are ``no deallocation''
  10970. -which is really only useful for demonstration programs, ``allocate and
  10971. -deallocate'' which minimises overall memory requirements at the expense of
  10972. -speed, and ``resize on demand'' which is useful for routines that are
  10973. -called repeatedly.  A new technique for static workspace arrays is to
  10974. -``register workspace variables''.
  10975. -
  10976. -
  10977. -2.1  NO DEALLOCATION
  10978. -
  10979. -   This is the strategy of allocating but never deallocating data
  10980. -structures.  This is only useful for demonstration programs run with small
  10981. -to medium size data structures.  For example, there could be a line
  10982. -
  10983. -  QR = m_copy(A,MNULL);     /* allocate memory for QR */
  10984. -
  10985. -to allocate the memory, but without the call M_FREE(QR); in it.  This can
  10986. -be acceptable if QR = m_copy(A,MNULL) is only executed once, and so the
  10987. -allocated memory never needs to be explicitly deallocated.
  10988. -
  10989. -   This would not be acceptable if QR = m_copy(A,MNULL) occurred inside a
  10990. -for loop.  If this were so, then memory would be ``lost'' as far as the
  10991. -program is concerned until there was insufficient space for allocating the
  10992. -next matrix for QR.  The next subsection shows how to avoid this.
  10993. -
  10994. -
  10995. -2.2  ALLOCATE AND DEALLOCATE
  10996. -
  10997. -   This is the most straightforward way of ensuring that memory is not
  10998. -lost.  With the example of allocating QR it would work like this:
  10999. -
  11000. -  for ( ... ; ... ; ... )
  11001. -  {
  11002. -    QR = m_copy(A,MNULL);    /* allocate memory for QR */
  11003. -                             /* could have been allocated by m_get() */
  11004. -    /* use QR */
  11005. -      ......
  11006. -      ......
  11007. -    /* no longer need QR for this cycle */
  11008. -    M_FREE(QR);             /* deallocate QR so memory can be reused */
  11009. -  }
  11010. -
  11011. -   The allocate and deallocate statements could also have come at the
  11012. -beginning and end of a function or procedure, so that when the function
  11013. -returns, all the memory that the function has allocated has been
  11014. -deallocated.
  11015. -
  11016. -   This is most suitable for functions or sections of code that are called
  11017. -repeatedly but involve fairly extensive calculations (at least a
  11018. -matrix-matrix multiply, or solving a system of equations).
  11019. -
  11020. -
  11021. -2.3  RESIZE ON DEMAND
  11022. -
  11023. -   This technique reduces the time involved in memory allocation for code
  11024. -that is repeatedly called or used, especially where the same size matrix or
  11025. -vector is needed.  For example, the vectors v1, v2, etc. in the
  11026. -Runge-Kutta routine rk4() are allocated according to this strategy:
  11027. -
  11028. -  rk4(...,x,...)
  11029. -  {
  11030. -     static VEC *v1=VNULL, *v2=VNULL, *v3=VNULL, *v4=VNULL, *temp=VNULL;
  11031. -     .......
  11032. -     v1   = v_resize(v1,x->dim);
  11033. -     v2   = v_resize(v2,x->dim);
  11034. -     v3   = v_resize(v3,x->dim);
  11035. -     v4   = v_resize(v4,x->dim);
  11036. -     temp = v_resize(temp,x->dim);
  11037. -     .......
  11038. -  }
  11039. -
  11040. -   The intention is that the rk4() routine is called repeatedly with the
  11041. -same size x vector.  It then doesn't make as much sense to allocate v1, v2
  11042. -etc.  whenever the function is called.  Instead, v_resize() only performs
  11043. -memory allocation if the memory already allocated to v1, v2 etc. is smaller
  11044. -than x->dim.
  11045. -
  11046. -   The vectors v1, v2 etc. are declared to be static to ensure that their
  11047. -values are not lost between function calls.  Variables that are declared
  11048. -static are set to NULL or zero by default.  So the declaration of v1, v2,
  11049. -etc., could be
  11050. -
  11051. -  static VEC *v1, *v2, *v3, *v4, *temp;
  11052. -
  11053. -   This strategy of resizing static workspace variables is not so useful if
  11054. -the object being allocated is extremely large.  The previous ``allocate and
  11055. -deallocate'' strategy is much more efficient for memory in those
  11056. -circumstances.  However, the following section shows how to get the best of
  11057. -both worlds.
  11058. -
  11059. -
  11060. -2.4  REGISTRATION OF WORKSPACE
  11061. -
  11062. -   From version 1.2 onwards, workspace variables can be registered so that
  11063. -the memory they reference can be freed up on demand.  To do this, the
  11064. -function containing the static workspace variables has to include calls to
  11065. -MEM_STAT_REG(var,type) where var is a pointer to a Meschach data type (such
  11066. -as VEC or MAT).  This call should be placed after the call to the
  11067. -appropriate resize function.  The type parameter should be a TYPE_... macro
  11068. -where the ``...'' is the name of a Meschach type such as VEC or MAT.  For
  11069. -example,
  11070. -
  11071. -  rk4(...,x,...)
  11072. -  {
  11073. -     static VEC *v1, *v2, *v3, *v4, *temp;
  11074. -       .......
  11075. -     v1   = v_resize(v1,x->dim);
  11076. -     MEM_STAT_REG(v1,TYPE_VEC);
  11077. -     v2   = v_resize(v2,x->dim);
  11078. -     MEM_STAT_REG(v2,TYPE_VEC);
  11079. -       ......
  11080. -  }
  11081. -
  11082. -Normally, these registered workspace variables remain allocated.  However,
  11083. -to implement the ``deallocate on exit'' approach, use the following code:
  11084. -
  11085. -  ......
  11086. -  mem_stat_mark(1);
  11087. -  rk4(...,x,...)
  11088. -  mem_stat_free(1);
  11089. -  ......
  11090. -
  11091. -   To keep the workspace vectors allocated for the duration of a loop, but
  11092. -then deallocated, use
  11093. -
  11094. -  ......
  11095. -  mem_stat_mark(1);
  11096. -  for (i = 0; i < N; i++ )
  11097. -    rk4(...,x,...);
  11098. -  mem_stat_free(1);
  11099. -  ......
  11100. -
  11101. -The number used in the mem_stat_mark() and mem_stat_free() calls is the
  11102. -workspace group number.  The call mem_stat_mark(1) designates 1 as the
  11103. -current workspace group number; the call mem_stat_free(1) deallocates (and
  11104. -sets to NULL) all static workspace variables registered as belonging to
  11105. -workspace group 1.
  11106. -
  11107. -
  11108. -
  11109. -3.  SIMPLE VECTOR OPERATIONS: AN RK4 ROUTINE
  11110. -
  11111. -   The main purpose of this example is to show how to deal with vectors and
  11112. -to compute linear combinations.
  11113. -
  11114. -   The problem here is to implement the standard 4th order Runge-Kutta
  11115. -method for the ODE
  11116. -
  11117. -  x'=f(t,x), x(t_0)=x_0 
  11118. -
  11119. -for x(t_i), i=1,2,3, where t_i=t_0+i*h and h is the step size.
  11120. -
  11121. -   The formulae for the 4th order Runge-Kutta method are:
  11122. -
  11123. -    x_i+1 = x_i+ h/6*(v_1+2*v_2+2*v_3+v_4),
  11124. -where
  11125. -    v_1 = f(t_i,x_i)
  11126. -    v_2 = f(t_i+h, x_i+h*v_1)
  11127. -    v_3 = f(t_i+h, x_i+h*v_2)
  11128. -    v_4 = f(t_i+h, x_i+h*v_3)
  11129. -
  11130. -where the v_i are vectors.
  11131. -
  11132. -   The procedure for implementing this method (rk4()) will be passed (a
  11133. -pointer to) the function f. The implementation of f could, in this system,
  11134. -create a vector to hold the return value each time it is called.  However,
  11135. -such a scheme is memory intensive and the calls to the memory allocation
  11136. -functions could easily dominate the time performed doing numerical
  11137. -computations.  So, the implementation of f will also be passed an already
  11138. -allocated vector to be filled in with the appropriate values.
  11139. -
  11140. -   The procedure rk4() will also be passed the current time t, the step
  11141. -size h, and the current value for x.  The time after the step will be
  11142. -returned by rk4().
  11143. -
  11144. -The code that does this follows.
  11145. -
  11146. -
  11147. -  #include "matrix.h"
  11148. -
  11149. -  /* rk4 - 4th order Runge-Kutta method */
  11150. -  double rk4(f,t,x,h)
  11151. -  double t, h;
  11152. -  VEC    *(*f)(), *x;
  11153. -  {
  11154. -     static VEC *v1=VNULL, *v2=VNULL, *v3=VNULL, *v4=VNULL;
  11155. -     static VEC *temp=VNULL;
  11156. -
  11157. -     /* do not work with NULL initial vector */
  11158. -     if ( x == VNULL )
  11159. -        error(E_NULL,"rk4");
  11160. -
  11161. -     /* ensure that v1, ..., v4, temp are of the correct size */
  11162. -     v1   = v_resize(v1,x->dim);
  11163. -     v2   = v_resize(v2,x->dim);
  11164. -     v3   = v_resize(v3,x->dim);
  11165. -     v4   = v_resize(v4,x->dim);
  11166. -     temp = v_resize(temp,x->dim);
  11167. -
  11168. -     /* register workspace variables */
  11169. -     MEM_STAT_REG(v1,TYPE_VEC);
  11170. -     MEM_STAT_REG(v2,TYPE_VEC);
  11171. -     MEM_STAT_REG(v3,TYPE_VEC);
  11172. -     MEM_STAT_REG(v4,TYPE_VEC);
  11173. -     MEM_STAT_REG(temp,TYPE_VEC);
  11174. -     /* end of memory allocation */
  11175. -
  11176. -     (*f)(t,x,v1);         /* most compilers allow: f(t,x,v1); */
  11177. -     v_mltadd(x,v1,0.5*h,temp);    /* temp = x+.5*h*v1 */
  11178. -     (*f)(t+0.5*h,temp,v2);
  11179. -     v_mltadd(x,v2,0.5*h,temp);    /* temp = x+.5*h*v2 */
  11180. -     (*f)(t+0.5*h,temp,v3);
  11181. -     v_mltadd(x,v3,h,temp);        /* temp = x+h*v3 */
  11182. -     (*f)(t+h,temp,v4);
  11183. -
  11184. -     /* now add: v1+2*v2+2*v3+v4 */
  11185. -     v_copy(v1,temp);              /* temp = v1 */
  11186. -     v_mltadd(temp,v2,2.0,temp);   /* temp = v1+2*v2 */
  11187. -     v_mltadd(temp,v3,2.0,temp);   /* temp = v1+2*v2+2*v3 */
  11188. -     v_add(temp,v4,temp);          /* temp = v1+2*v2+2*v3+v4 */
  11189. -
  11190. -     /* adjust x */
  11191. -     v_mltadd(x,temp,h/6.0,x);     /* x = x+(h/6)*temp */
  11192. -
  11193. -     return t+h;                   /* return the new time */
  11194. -  }
  11195. -
  11196. -
  11197. -   Note that the last parameter of f() is where the output is placed.
  11198. -Often this can be NULL in which case the appropriate data structure is
  11199. -allocated and initialised.  Note also that this routine can be used for
  11200. -problems of arbitrary size, and the dimension of the problem is determined
  11201. -directly from the data given.  The vectors v_1,...,v_4 are created to have
  11202. -the correct size in the lines
  11203. -
  11204. -  ....
  11205. -  v1 = v_resize(v1,x->dim);
  11206. -  v2 = v_resize(v2,x->dim);
  11207. -  ....
  11208. -
  11209. -   Here v_resize(v,dim) resizes the VEC structure v to hold a vector of
  11210. -length dim.  If v is initially NULL, then this creates a new vector of
  11211. -dimension dim, just as v_get(dim) would do.  For the above piece of code to
  11212. -work correctly, v1, v2 etc., must be initialised to be NULL vectors.  This
  11213. -is done by the declaration
  11214. -
  11215. -  static VEC *v1=VNULL, *v2=VNULL, *v3=VNULL, *v4=VNULL;
  11216. -
  11217. -or
  11218. -
  11219. -  static VEC *v1, *v2, *v3, *v4;
  11220. -
  11221. -The operations of vector addition and scalar addition are really the only
  11222. -vector operations that need to be performed in rk4.  Vector addition is
  11223. -done by v_add(v1,v2,out), where out=v1+v2, and scalar multiplication by
  11224. -sv_mlt(scale,v,out), where out=scale*v.
  11225. -
  11226. -These can be combined into a single operation v_mltadd(v1,v2,scale,out),
  11227. -where out=v1+scale*v2.  As many operations in numerical mathematics involve
  11228. -accumulating scalar multiples, this is an extremely useful operation, as we
  11229. -can see above.  For example:
  11230. -
  11231. -  v_mltadd(x,v1,0.5*h,temp);    /* temp = x+0.5*h*v1 */
  11232. -
  11233. -   We also need a number of ``utility'' operations.  For example v_copy(in,
  11234. -out) copies the vector in to out.  There is also v_zero(v) to zero a vector
  11235. -v.
  11236. -
  11237. -   Here is an implementation of the function f for simple harmonic motion:
  11238. -
  11239. -  /* f - right-hand side of ODE solver */
  11240. -  VEC    *f(t,x,out)
  11241. -  VEC    *x, *out;
  11242. -  double    t;
  11243. -  {
  11244. -    if ( x == VNULL || out == VNULL )
  11245. -        error(E_NULL,"f");
  11246. -    if ( x->dim != 2 || out->dim != 2 )
  11247. -        error(E_SIZES,"f");
  11248. -
  11249. -    out->ve[0] = x->ve[1];
  11250. -    out->ve[1] = - x->ve[0];
  11251. -
  11252. -    return out;
  11253. -  }
  11254. -
  11255. -  As can be seen, most of this code is error checking code, which, of
  11256. -course, makes the routine safer but a little slower.  For a procedure like
  11257. -f() it is probably not necessary, although then the main program would have
  11258. -to perform checking to ensure that the vectors involved have the correct
  11259. -size etc.  The ith component of a vector x is x->ve[i], and indexing is
  11260. -zero-relative (i.e., the ``first'' component is component 0).  The ODE
  11261. -described above is for simple harmonic motion:
  11262. -    x_0'=x_1 ,  x_1'=-x_0 , or equivalently,  x_0''+ x_0 = 0 .
  11263. -
  11264. -  Here is the main program:
  11265. -
  11266. -
  11267. -  #include <stdio.h>
  11268. -  #include "matrix.h"
  11269. -
  11270. -  main()
  11271. -  {
  11272. -    VEC        *x;
  11273. -    VEC        *f();
  11274. -    double     h, t, t_fin;
  11275. -    double     rk4();
  11276. -
  11277. -    input("Input initial time: ", "%lf", &t);
  11278. -    input("Input final time: ",  "%lf", &t_fin);
  11279. -    x = v_get(2);        /* this is the size needed by f() */
  11280. -    prompter("Input initial state:\n");    x = v_input(VNULL);
  11281. -    input("Input step size: ", "%lf", &h);
  11282. -
  11283. -    printf("# At time %g, the state is\n",t); 
  11284. -    v_output(x);
  11285. -    while ( t < t_fin )
  11286. -    {
  11287. -        t = rk4(f,t,x,min(h,t_fin-t));   /* new t is returned */
  11288. -        printf("# At time %g, the state is\n",t);
  11289. -        v_output(x);
  11290. -    t += h;
  11291. -    }
  11292. -  }
  11293. -
  11294. -   The initial values are entered as a vector by v_input().  If v_input()
  11295. -is passed a vector, then this vector will be used to store the input, and
  11296. -this vector has the size that x had on entry to v_input().  The original
  11297. -values of x are also used as a prompt on input from a tty.  If a NULL is
  11298. -passed to v_input() then v_input() will return a vector of whatever size
  11299. -the user inputs.  So, to ensure that only a two-dimensional vector is used
  11300. -for the initial conditions (which is what f() is expecting) we use
  11301. -
  11302. -    x = v_get(2);     x = v_input(x);
  11303. -
  11304. -   To compile the program under Unix, if it is in a file tutorial.c:
  11305. -
  11306. -    cc -o tutorial tutorial.c meschach.a
  11307. -
  11308. -or, if you have an ANSI compiler,
  11309. -
  11310. -    cc -DANSI_C -o tutorial tutorial.c meschach.a
  11311. -
  11312. -   Here is a sample session with the above program: 
  11313. -
  11314. - tutorial
  11315. -
  11316. -  Input initial time: 0
  11317. -  Input final time: 1
  11318. -  Input initial state:
  11319. -  Vector: dim: 2
  11320. -  entry 0: -1
  11321. -  entry 1: b
  11322. -  entry 0: old             -1 new: 1
  11323. -  entry 1: old              0 new: 0
  11324. -  Input step size: 0.1
  11325. -  At time 0, the state is
  11326. -  Vector: dim: 2
  11327. -             1              0 
  11328. -  At time 0.1, the state is
  11329. -  Vector: dim: 2
  11330. -    0.995004167  -0.0998333333 
  11331. -      .................
  11332. -  At time 1, the state is
  11333. -  Vector: dim: 2
  11334. -    0.540302967   -0.841470478 
  11335. -
  11336. -   By way of comparison, the state at t=1 for the true solution is
  11337. -     x_0(1)=0.5403023058 , x_1(1)=-0.8414709848 .  
  11338. -The ``b'' that is typed in entering the x vector allows the user to alter
  11339. -previously entered components. In this case once this is done, the user is
  11340. -prompted with the old values when entering the new values.  The user can
  11341. -also type in ``f'' for skipping over the vector's components, which are
  11342. -then unchanged.  If an incorrectly sized initial value vector x is given,
  11343. -the error handler comes into action:
  11344. -
  11345. -  Input initial time: 0
  11346. -  Input final time: 1
  11347. -  Input initial state:
  11348. -  Vector: dim: 3
  11349. -  entry 0: 3
  11350. -  entry 1: 2
  11351. -  entry 2: -1
  11352. -  Input step size: 0.1
  11353. -  At time 0, the state is
  11354. -  Vector: dim: 3
  11355. -             3              2             -1 
  11356. -
  11357. -  "tutorial.c", line 79: sizes of objects don't match in function f()
  11358. -  Sorry, aborting program
  11359. -
  11360. -   The error handler prints out the error message giving the source code
  11361. -file and line number as well as the function name where the error was
  11362. -raised.  The relevant section of f() in file tutorial.c is:
  11363. -
  11364. -  if ( x->dim != 2 || out->dim != 2 )
  11365. -     error(E_SIZES,"f");               /* line 79 */
  11366. -
  11367. -
  11368. -   The standard routines in this system perform error checking of this
  11369. -type, and also checking for undefined results such as division by zero in
  11370. -the routines for solving systems of linear equations.  There are also error
  11371. -messages for incorrectly formatted input and end-of-file conditions.
  11372. -
  11373. -   To round off the discussion of this program, note that we have seen
  11374. -interactive input of vectors.  If the input file or stream is not a tty
  11375. -(e.g., a file, a pipeline or a device) then it expects the input to have
  11376. -the same form as the output for each of the data structures.  Each of the
  11377. -input routines (v_input(), m_input(), px_input()) skips over ``comments''
  11378. -in the input data, as do the macros input() and finput().  Anything from a
  11379. -`#' to the end of the line (or EOF) is considered to be a comment.  For
  11380. -example, the initial value problem could be set up in a file ivp.dat as:
  11381. -
  11382. -  # Initial time
  11383. -  0
  11384. -  # Final time
  11385. -  1
  11386. -  # Solution is x(t) = (cos(t),-sin(t))
  11387. -  # x(0) =
  11388. -  Vector: dim: 2
  11389. -  1       0
  11390. -  # Step size
  11391. -  0.1
  11392. -
  11393. -   The output of the above program with the above input (from a file) gives
  11394. -essentially the same output as shown above, except that no prompts are sent
  11395. -to the screen.
  11396. -
  11397. -
  11398. -
  11399. -4.  USING ROUTINES FOR LISTS OF ARGUMENTS
  11400. -
  11401. -   Some of the most common routines have variants that take a variable
  11402. -number of arguments.  These are the routines .._get_vars(), .._resize_vars()
  11403. -and .._free_vars().  These correspond to the the basic routines .._get(),
  11404. -.._resize() and .._free() respectively.  Also there is the
  11405. -mem_stat_reg_vars() routine which registers a list of static workspace
  11406. -variables. This corresponds to mem_stat_reg_list() for a single variable.
  11407. -
  11408. -   Here is an example of how to use these functions.  This example also
  11409. -uses the routine v_linlist() to compute a linear combination of vectors.
  11410. -Note that the code is much more compact, but don't forget that these
  11411. -``..._vars()'' routines usually need the address-of operator ``&'' and NULL
  11412. -termination of the arguments to work correctly.
  11413. -
  11414. -
  11415. -  #include "matrix.h"
  11416. -
  11417. -  /* rk4 - 4th order Runge-Kutta method */
  11418. -  double rk4(f,t,x,h)
  11419. -  double t, h;
  11420. -  VEC    *(*f)(), *x;
  11421. -  {
  11422. -    static VEC *v1, *v2, *v3, *v4, *temp;
  11423. -
  11424. -    /* do not work with NULL initial vector */
  11425. -    if ( x == VNULL )        
  11426. -    error(E_NULL,"rk4");
  11427. -
  11428. -    /* ensure that v1, ..., v4, temp are of the correct size */
  11429. -    v_resize_vars(x->dim, &v1, &v2, &v3, &v4, &temp, NULL);
  11430. -
  11431. -    /* register workspace variables */
  11432. -    mem_stat_reg_vars(0, TYPE_VEC, &v1, &v2, &v3, &v4, &temp, NULL);
  11433. -    /* end of memory allocation */
  11434. -
  11435. -    (*f)(t,x,v1);             v_mltadd(x,v1,0.5*h,temp);
  11436. -    (*f)(t+0.5*h,temp,v2);    v_mltadd(x,v2,0.5*h,temp);
  11437. -    (*f)(t+0.5*h,temp,v3);    v_mltadd(x,v3,h,temp);
  11438. -    (*f)(t+h,temp,v4);
  11439. -
  11440. -    /* now add: temp = v1+2*v2+2*v3+v4 */
  11441. -    v_linlist(temp, v1, 1.0, v2, 2.0, v3, 2.0, v4, 1.0, VNULL);
  11442. -    /* adjust x */
  11443. -    v_mltadd(x,temp,h/6.0,x);     /* x = x+(h/6)*temp */
  11444. -
  11445. -    return t+h;                   /* return the new time */
  11446. -  }
  11447. -
  11448. -
  11449. -
  11450. -5.  A LEAST SQUARES PROBLEM
  11451. -
  11452. -   Here we need to use matrices and matrix factorisations (in particular, a
  11453. -QR factorisation) in order to find the best linear least squares solution
  11454. -to some data.  Thus in order to solve the (approximate) equations
  11455. -      A*x = b,
  11456. -where A is an m x n matrix (m > n) we really need to solve the optimisation
  11457. -problem
  11458. -      min_x ||Ax-b||^2.  
  11459. -
  11460. -   If we write A=QR where Q is an orthogonal m x m matrix and R is an upper
  11461. -triangular m x n matrix then (we use 2-norm)
  11462. -
  11463. -    ||A*x-b||^2 = ||R*x-Q^T*b||^2 = || R_1*x - Q_1^T*b||^2 + ||Q_2^T*b||^2
  11464. -
  11465. -where R_1 is an n x n upper triangular matrix.  If A has full rank then R_1
  11466. -will be an invertible matrix, and the best least squares solution of A*x=b
  11467. -is x= R_1^{-1}*Q_1^T*b .
  11468. -
  11469. -   These calculations can be be done quite easily as there is a QRfactor()
  11470. -function available with the system.  QRfactor() is declared to have the
  11471. -prototype
  11472. -
  11473. -    MAT  *QRfactor(MAT *A, VEC *diag);
  11474. -
  11475. -   The matrix A is overwritten with the factorisation of A ``in compact
  11476. -form''; that is, while the upper triangular part of A is indeed the R
  11477. -matrix described above, the Q matrix is stored as a collection of
  11478. -Householder vectors in the strictly lower triangular part of A and in the
  11479. -diag vector.  The QRsolve() function knows and uses this compact form and
  11480. -solves Q*R*x=b with the call QRsolve(A,diag,b,x), which also returns x.
  11481. -
  11482. -   Here is the code to obtain the matrix A, perform the QR factorisation,
  11483. -obtain the data vector b, solve for x, and determine what the norm of the
  11484. -errors ( ||Ax-b||_2 ) is.
  11485. -
  11486. -
  11487. -  #include "matrix2.h"
  11488. -
  11489. -  main()
  11490. -  {
  11491. -    MAT *A, *QR;
  11492. -    VEC *b, *x, *diag;
  11493. -
  11494. -    /* read in A matrix */
  11495. -    printf("Input A matrix:");
  11496. -
  11497. -    A = m_input(MNULL);     /* A has whatever size is input */
  11498. -
  11499. -    if ( A->m < A->n )
  11500. -    {
  11501. -        printf("Need m >= n to obtain least squares fit");
  11502. -        exit(0);
  11503. -    }
  11504. -    printf("# A =");       m_output(A);
  11505. -    diag = v_get(A->m);
  11506. -
  11507. -    /* QR is to be the QR factorisation of A */
  11508. -    QR = m_copy(A,MNULL);
  11509. -    QRfactor(QR,diag);   
  11510. -
  11511. -    /* read in b vector */
  11512. -    printf("Input b vector:");
  11513. -    b = v_get(A->m);
  11514. -    b = v_input(b);
  11515. -    printf("# b =");       v_output(b);
  11516. -
  11517. -    /* solve for x */
  11518. -    x = QRsolve(QR,diag,b,VNULL);
  11519. -    printf("Vector of best fit parameters is");
  11520. -    v_output(x);
  11521. -
  11522. -    /* ... and work out norm of errors... */
  11523. -    printf("||A*x-b|| = %g\n",
  11524. -    v_norm2(v_sub(mv_mlt(A,x,VNULL),b,VNULL)));
  11525. -  }
  11526. -
  11527. -   Note that as well as the usual memory allocation functions like m_get(),
  11528. -the I/O functions like m_input() and m_output(), and the
  11529. -factorise-and-solve functions QRfactor() and QRsolve(), there are also
  11530. -functions for matrix-vector multiplication:
  11531. -     mv_mlt(MAT *A, VEC *x, VEC *out)  
  11532. -and also vector-matrix multiplication (with the vector on the left):
  11533. -     vm_mlt(MAT *A, VEC *x, VEC *out), 
  11534. -with out=x^T A.  There are also functions to perform matrix arithmetic -
  11535. -matrix addition m_add(), matrix-scalar multiplication sm_mlt(),
  11536. -matrix-matrix multiplication m_mlt().
  11537. -
  11538. -   Several different sorts of matrix factorisation are supported: LU
  11539. -factorisation (also known as Gaussian elimination) with partial pivoting,
  11540. -by LUfactor() and LUsolve().  Other factorisation methods include Cholesky
  11541. -factorisation CHfactor() and CHsolve(), and QR factorisation with column
  11542. -pivoting QRCPfactor().
  11543. -
  11544. -   Pivoting involve permutations which have their own PERM data structure.
  11545. -Permutations can be created by px_get(), read and written by px_input() and
  11546. -px_output(), multiplied by px_mlt(), inverted by px_inv() and applied to
  11547. -vectors by px_vec().
  11548. -
  11549. -The above program can be put into a file leastsq.c and compiled under Unix
  11550. -using
  11551. -
  11552. -    cc -o leastsq leastsq.c meschach.a -lm
  11553. -
  11554. -A sample session using leastsq follows:
  11555. -
  11556. -
  11557. -  Input A matrix:
  11558. -  Matrix: rows cols:5 3
  11559. -  row 0:
  11560. -  entry (0,0): 3
  11561. -  entry (0,1): -1
  11562. -  entry (0,2): 2
  11563. -  Continue: 
  11564. -  row 1:
  11565. -  entry (1,0): 2
  11566. -  entry (1,1): -1
  11567. -  entry (1,2): 1
  11568. -  Continue: n
  11569. -  row 1:
  11570. -  entry (1,0): old              2 new: 2
  11571. -  entry (1,1): old             -1 new: -1
  11572. -  entry (1,2): old              1 new: 1.2
  11573. -  Continue: 
  11574. -  row 2:
  11575. -  entry (2,0): old              0 new: 2.5
  11576. -  ....
  11577. -  ....             (Data entry)
  11578. -  ....
  11579. -  # A =
  11580. -  Matrix: 5 by 3
  11581. -  row 0:              3             -1              2 
  11582. -  row 1:              2             -1            1.2 
  11583. -  row 2:            2.5              1           -1.5 
  11584. -  row 3:              3              1              1 
  11585. -  row 4:             -1              1           -2.2 
  11586. -  Input b vector:
  11587. -  entry 0: old              0 new: 5
  11588. -  entry 1: old              0 new: 3
  11589. -  entry 2: old              0 new: 2
  11590. -  entry 3: old              0 new: 4
  11591. -  entry 4: old              0 new: 6
  11592. -  # b =
  11593. -  Vector: dim: 5
  11594. -           5            3            2            4            6 
  11595. -  Vector of best fit parameters is
  11596. -  Vector: dim: 3
  11597. -     1.47241555   -0.402817858    -1.14411815 
  11598. -  ||A*x-b|| = 6.78938
  11599. -
  11600. -
  11601. -   The Q matrix can be obtained explicitly by the routine makeQ().  The Q
  11602. -matrix can then be used to obtain an orthogonal basis for the range of A .
  11603. -An orthogonal basis for the null space of A can be obtained by finding the
  11604. -QR-factorisation of A^T .
  11605. -
  11606. -
  11607. -
  11608. -6.  A SPARSE MATRIX EXAMPLE
  11609. -
  11610. -   To illustrate the sparse matrix routines, consider the problem of
  11611. -solving Poisson's equation on a square using finite differences, and
  11612. -incomplete Cholesky factorisation.  The actual equations to solve are
  11613. -
  11614. -    u_{i,j+1} + u_{i,j-1} + u_{i+1,j} + u_{i-1,j} - 4*u_{i,j} =
  11615. -       h^2*f(x_i,y_j),  for  i,j=1,...,N   
  11616. -
  11617. -where u_{0,j} = u_{i,0} = u_{N+1,j} = u_{i,N+1} = 0 for i,j=1,...,N and h
  11618. -is the common distance between grid points.
  11619. -
  11620. -   The first task is to set up the matrix describing this system of linear
  11621. -equations.  The next is to set up the right-hand side.  The third is to
  11622. -form the incomplete Cholesky factorisation of this matrix, and finally to
  11623. -use the sparse matrix conjugate gradient routine with the incomplete
  11624. -Cholesky factorisation as preconditioner.
  11625. -
  11626. -   Setting up the matrix and right-hand side can be done by the following
  11627. -code:
  11628. -
  11629. -
  11630. -  #define N 100
  11631. -  #define index(i,j) (N*((i)-1)+(j)-1)
  11632. -  ......
  11633. -  A = sp_get(N*N,N*N,5);
  11634. -  b = v_get(N*N);
  11635. -  h = 1.0/(N+1);      /* for a unit square */
  11636. -  ......
  11637. -
  11638. -  for ( i = 1; i <= N; i++ )
  11639. -    for ( j = 1; j <= N; j++ )
  11640. -    {
  11641. -        if ( i < N )
  11642. -            sp_set_val(A,index(i,j),index(i+1,j),-1.0);
  11643. -        if ( i > 1 )
  11644. -            sp_set_val(A,index(i,j),index(i-1,j),-1.0);
  11645. -        if ( j < N )
  11646. -            sp_set_val(A,index(i,j),index(i,j+1),-1.0);
  11647. -        if ( j > 1 )
  11648. -            sp_set_val(A,index(i,j),index(i,j-1),-1.0);
  11649. -        sp_set_val(A,index(i,j),index(i,j),4.0);
  11650. -        b->ve[index(i,j)] = -h*h*f(h*i,h*j);
  11651. -    }
  11652. -
  11653. -   Once the matrix and right-hand side are set up, the next task is to
  11654. -compute the sparse incomplete Cholesky factorisation of A.  This must be
  11655. -done in a different matrix, so A must be copied.
  11656. -
  11657. -  LLT = sp_copy(A);
  11658. -  spICHfactor(LLT);
  11659. -
  11660. -Now when that is done, the remainder is easy:
  11661. -
  11662. -  out = v_get(A->m);
  11663. -  ......
  11664. -  iter_spcg(A,LLT,b,1e-6,out,1000,&num_steps);
  11665. -  printf("Number of iterations = %d\n",num_steps);
  11666. -  ......
  11667. -
  11668. -and the output can be used in whatever way desired.
  11669. -
  11670. -   For graphical output of the results, the solution vector can be copied
  11671. -into a square matrix, which is then saved in MATLAB format using m_save(),
  11672. -and graphical output can be produced by MATLAB.
  11673. -
  11674. -
  11675. -
  11676. -7.  HOW DO I ....?
  11677. -
  11678. -   For the convenience of the user, here a number of common tasks that
  11679. -people need to perform frequently, and how to perform the computations
  11680. -using Meschach.
  11681. -
  11682. -
  11683. -7.1 .... SOLVE A SYSTEM OF LINEAR EQUATIONS ?
  11684. -
  11685. -   If you wish to solve Ax=b for x given A and b (without destroying A),
  11686. -then the following code will do this:
  11687. -
  11688. -  VEC   *x, *b;
  11689. -  MAT    *A, *LU;
  11690. -  PERM    *pivot;
  11691. -  ......
  11692. -  LU = m_get(A->m,A->n);
  11693. -  LU = m_copy(A,LU);
  11694. -  pivot = px_get(A->m);
  11695. -  LUfactor(LU,pivot);
  11696. -  /* set values of b here */
  11697. -  x = LUsolve(LU,pivot,b,VNULL);
  11698. -
  11699. -
  11700. -7.2  .... SOLVE A LEAST-SQUARES PROBLEM ?
  11701. -
  11702. -   To minimise ||Ax-b||_2^2 = sum_i ((Ax)_i-b_i)^2, the most reliable
  11703. -method is based on the QR-factorisation.  The following code performs this
  11704. -calculation assuming that A is m x n with m > n :
  11705. -
  11706. -  MAT    *A, *QR;
  11707. -  VEC    *diag, *b, *x;
  11708. -  ......
  11709. -  QR = m_get(A->m,A->n);
  11710. -  QR = m_copy(A,QR);
  11711. -  diag = v_get(A->n);
  11712. -  QRfactor(QR,diag);
  11713. -  /* set values of b here */
  11714. -  x = QRsolve(QR,diag,b,x);
  11715. -
  11716. -
  11717. -7.3  .... FIND ALL THE EIGENVALUES (AND EIGENVECTORS) OF A GENERAL MATRIX ?
  11718. -
  11719. -   The best method is based on the Schur decomposition.  For symmetric
  11720. -matrices, the eigenvalues and eigenvectors can be computed by a single call
  11721. -to symmeig().  For non-symmetric matrices, the situation is more complex
  11722. -and the problem of finding eigenvalues and eigenvectors can become quite
  11723. -ill-conditioned.  Provided the problem is not too ill-conditioned, the
  11724. -following code should give accurate results:
  11725. -
  11726. -
  11727. -  /* A is the matrix whose eigenvalues and eigenvectors are sought */
  11728. -  MAT    *A, *T, *Q, *X_re, *X_im;
  11729. -  VEC    *evals_re, *evals_im;
  11730. -  ......
  11731. -  Q = m_get(A->m,A->n);
  11732. -  T = m_copy(A,MNULL);
  11733. -
  11734. -  /* compute Schur form: A = Q*T*Q^T */
  11735. -  schur(T,Q);
  11736. -  /* extract eigenvalues */
  11737. -  evals_re = v_get(A->m);
  11738. -  evals_im = v_get(A->m);
  11739. -  schur_evals(T,evals_re,evals_im);
  11740. -
  11741. -  /* Q not needed for eiegenvalues */
  11742. -  X_re = m_get(A->m,A->n);
  11743. -  X_im = m_get(A->m,A->n);
  11744. -  schur_vecs(T,Q,X_re,X_im);
  11745. -  /* k'th eigenvector is k'th column of (X_re + i*X_im) */
  11746. -
  11747. -
  11748. -
  11749. -7.4  .... SOLVE A LARGE, SPARSE, POSITIVE DEFINITE SYSTEM OF EQUATIONS ?
  11750. -
  11751. -   An example of a large, sparse, positive definite matrix is the matrix
  11752. -obtained from a finite-difference approximation of the Laplacian operator.
  11753. -If an explicit representation of such a matrix is available, then the
  11754. -following code is suggested as a reasonable way of computing solutions:
  11755. -
  11756. -
  11757. -  /* A*x == b is the system to be solved */
  11758. -  SPMAT *A, *LLT;
  11759. -  VEC    *x, *b;
  11760. -  int   num_steps;
  11761. -  ......
  11762. -  /* set up A and b */
  11763. -  ......
  11764. -  x = m_get(A->m);
  11765. -  LLT = sp_copy(A);
  11766. -
  11767. -  /* preconditioning using the incomplete Cholesky factorisation */
  11768. -  spICHfactor(LLT);
  11769. -
  11770. -  /* now use pre-conditioned conjugate gradients */
  11771. -  x = iter_spcg(A,LLT,b,1e-7,x,1000,&num_steps);
  11772. -  /* solution computed to give a relative residual of 10^-7 */
  11773. -
  11774. -
  11775. -   If explicitly storing such a matrix takes up too much memory, then if
  11776. -you can write a routine to perform the calculation of A*x for any given x ,
  11777. -the following code may be more suitable (if slower):
  11778. -
  11779. -
  11780. -  VEC  *mult_routine(user_def,x,out)
  11781. -  void *user_def;
  11782. -  VEC  *x, *out;
  11783. -  {
  11784. -     /* compute out = A*x */
  11785. -     ......
  11786. -     return out;
  11787. -  }
  11788. -
  11789. -
  11790. -  main()
  11791. -  {
  11792. -    ITER *ip;
  11793. -    VEC  *x, *b;
  11794. -      ......
  11795. -    b = v_get(BIG_DIM);     /* right-hand side */
  11796. -    x = v_get(BIG_DIM);     /* solution */
  11797. -
  11798. -    /* set up b */
  11799. -      ......
  11800. -    ip = iter_get(b->dim, x->dim);
  11801. -    ip->b = v_copy(b,ip->b);
  11802. -    ip->info = NULL;        /* if you don't want information
  11803. -                                   about solution process */
  11804. -    v_zero(ip->x);          /* initial guess is zero */
  11805. -    iter_Ax(ip,mult_routine,user_def);
  11806. -    iter_cg(ip);
  11807. -    printf("# Solution is:\n");   v_output(ip->x);
  11808. -      ......
  11809. -    ITER_FREE(ip);          /* destroy ip */
  11810. -  }
  11811. -
  11812. -   The user_def argument is for a pointer to a user-defined structure
  11813. -(possibly NULL, if you don't need this) so that you can write a common
  11814. -function for handling a large number of different circumstances.
  11815. -
  11816. -
  11817. -
  11818. -8. MORE ADVANCED TOPICS
  11819. -
  11820. -   Read this if you are interested in using Meschach library as a base for
  11821. -applications. As an example we show how to implement a new type for 3
  11822. -dimensional matrices and incorporate this new type into the Meschach
  11823. -system. Usually this part of Meschach is transparent to a user.  But a more
  11824. -advanced user can take advantage of these routines. We do not describe
  11825. -the routines in detail here, but we want to give a rather broad picture of
  11826. -what can be done.  By the system we mainly mean the system of delivering
  11827. -information on the number of bytes of allocated memory and routines for
  11828. -deallocating static variables by mem_stat_... routines.
  11829. -
  11830. -   First we introduce a concept of a list of types. By a list of types we
  11831. -mean a set of different types with corresponding routines for creating
  11832. -these types, destroying and resizing them.  Each type list has a number.
  11833. -The list 0 is a list of standard Meschach types such as MAT or VEC. Other
  11834. -lists can be defined by a user or a application (based on Meschach). The
  11835. -user can attach his/her own list to the system by the routine
  11836. -mem_attach_list(). Sometimes it is worth checking if a list number is
  11837. -already used by another application. It can be done by
  11838. -mem_is_list_attached(ls_num), which returns TRUE if the number ls_num 
  11839. -is used. And such a list can be removed from the system by
  11840. -mem_free_list(ls_num) if necessary.
  11841. -
  11842. -   We describe arguments required by mem_attach_list(). The prototype of
  11843. -this function is as follow
  11844. -  
  11845. - int mem_attach_list(int ls_num, int ntypes, char *type_names[],
  11846. -                 int (*free_funcs[])(), MEM_ARRAY sum[]);
  11847. -
  11848. -where the structure MEM_ARRAY has two members: "bytes" of type long and
  11849. -"numvar" of type int.  The frst argument is the list number.  Note that you
  11850. -cannot overwrite another list.  To do this remove first the old list (by
  11851. -mem_free_list()) or choose another number.  The next argument is the number
  11852. -of types which are on the list.  This number cannot be changed during
  11853. -running a program. The third argument is an array containing the names of
  11854. -types (these are character strings).  The fourth one is an array of
  11855. -functions deallocating variables of the corresponding type.  And the last
  11856. -argument is the local array where information about the number of bytes of
  11857. -allocated/deallocated memory (member bytes) and the number of allocated
  11858. -variables (member numvar) are gathered. The functions which send
  11859. -information to this array are mem_bytes_list() and mem_numvar_list().
  11860. -
  11861. -
  11862. -Example:  The routines described here are in the file tutadv.c.
  11863. -Firstly we define some macros and a type for 3 dimensional matrices.
  11864. -
  11865. -#include "matrix.h"
  11866. -#define M3D_LIST    3      /* list number */
  11867. -#define TYPE_MAT3D  0      /* the number of a type */
  11868. -/* type for 3 dimensional matrices */
  11869. -typedef struct {
  11870. -    int l,m,n;    /* actual dimensions */
  11871. -    int max_l, max_m, max_n;    /* maximal dimensions */
  11872. -    Real ***me;    /* pointer to matrix elements */
  11873. -                   /* we do not consider segmented memory */
  11874. -        Real *base, **me2d;  /* me and me2d are additional pointers 
  11875. -                to base */
  11876. -} MAT3D;
  11877. -
  11878. -
  11879. -Now we need two routines: one for allocating memory for 3 dimensional
  11880. -matrices and the other for deallocating it. It can be useful to have a
  11881. -routine for resizing 3 dimensional matrices but we do not use it here.
  11882. -Note the use of mem_bytes_list() and mem_numvar_list() to notify the change
  11883. -in the number of structures and bytes in use.
  11884. -
  11885. -/* function for creating a variable of MAT3D type */
  11886. -
  11887. -MAT3D *m3d_get(l,m,n)
  11888. -int l,m,n;
  11889. -{
  11890. -  MAT3D *mat;
  11891. -  ....
  11892. -  /* alocate memory for structure */
  11893. -  if ((mat = NEW(MAT3D)) == (MAT3D *)NULL)
  11894. -    error(E_MEM,"m3d_get");
  11895. -  else if (mem_info_is_on()) {
  11896. -    /* record how many bytes are allocated to structure */
  11897. -    mem_bytes_list(TYPE_MAT3D,0,sizeof(MAT3D),M3D_LIST);
  11898. -    /* record a new allocated variable */
  11899. -    mem_numvar_list(TYPE_MAT3D,1,M3D_LIST);
  11900. -  }
  11901. -  ....
  11902. -  /* allocate memory for 3D array */
  11903. -  if ((mat->base = NEW_A(l*m*n,Real)) == (Real *)NULL) 
  11904. -    error(E_MEM,"m3d_get");
  11905. -  else if (mem_info_is_on())
  11906. -    mem_bytes_list(TYPE_MAT3D,0,l*m*n*sizeof(Real),M3D_LIST);
  11907. -  ....
  11908. -  return mat;
  11909. -}
  11910. -
  11911. -/* deallocate a variable of type MAT3D */
  11912. -
  11913. -int m3d_free(mat)
  11914. -MAT3D *mat;
  11915. -{
  11916. -  /* do not try to deallocate the NULL pointer */
  11917. -  if (mat == (MAT3D *)NULL)
  11918. -    return -1;
  11919. -  ....
  11920. -  /* first deallocate base */
  11921. -  if (mat->base != (Real *)NULL) {
  11922. -    if (mem_info_is_on())
  11923. -    /* record how many bytes is deallocated */
  11924. -      mem_bytes_list(TYPE_MAT3D,mat->max_l*mat->max_m*mat->max_n*sizeof(Real),
  11925. -             0,M3D_LIST);
  11926. -    free((char *)mat->base);
  11927. -  }
  11928. -  ....
  11929. -  /* deallocate  MAT3D structure */
  11930. -  if (mem_info_is_on()) {
  11931. -    mem_bytes_list(TYPE_MAT3D,sizeof(MAT3D),0,M3D_LIST);
  11932. -    mem_numvar_list(TYPE_MAT3D,-1,M3D_LIST);
  11933. -  }
  11934. -  free((char *)mat);
  11935. -
  11936. -  ....
  11937. -  free((char *)mat);
  11938. -
  11939. -  return 0;
  11940. -}
  11941. -
  11942. -
  11943. -We can now create the arrays necessary for mem_attach_list(). Note that
  11944. -m3d_sum can be static if it is in the same file as main(), where
  11945. -mem_attach_list is called. Otherwise it must be global.
  11946. -
  11947. -
  11948. -char *m3d_names[] = {
  11949. -  "MAT3D"
  11950. -};
  11951. -
  11952. -#define M3D_NUM  (sizeof(m3d_names)/sizeof(*m3d_names))
  11953. -
  11954. -int (*m3d_free_funcs[M3D_NUM])() = {
  11955. -  m3d_free
  11956. -}
  11957. -
  11958. -static MEM_ARRAY m3d_sum[M3D_NUM];
  11959. -
  11960. -
  11961. -The last thing is to attach the list to the system.
  11962. -
  11963. -void main()
  11964. -{
  11965. -  MAT3D *M;
  11966. -  ....
  11967. -
  11968. -  mem_info_on(TRUE);    /* switch memory info on */
  11969. -  /* attach the new list */
  11970. -  mem_attach_list(M3D_LIST,M3D_NUM,m3d_names,m3d_free_funcs,m3d_sum);
  11971. -  ....
  11972. -  M = m3d_get(3,4,5);
  11973. -  ....
  11974. -  /* making use of M->me[i][j][k], where i,j,k are non-negative and 
  11975. -    i < 3, j < 4, k < 5 */
  11976. -  ....
  11977. -  mem_info_file(stdout,M3D_LIST);  /* info on the number of allocated 
  11978. -                      bytes of memory for types 
  11979. -                       on the list M3D_LIST */
  11980. -  ....
  11981. -  m3d_free(M);  /* if M is not necessary */
  11982. -  ....
  11983. -}
  11984. -
  11985. -
  11986. -We can now use the function mem_info_file() for getting information about
  11987. -the number of bytes of allocated memory and number of allocated variables
  11988. -of type MAT3D; mem_stat_reg_list() for registering variables of this type
  11989. -and mem_stat_mark() and mem_stat_free_list() for deallocating static
  11990. -variables of this type.
  11991. -
  11992. -
  11993. -
  11994. -In the similar way you can create you own list of errors and attach it to
  11995. -the system. See the functions: 
  11996. -
  11997. -  int err_list_attach(int list_num, int list_len, char **err_ptr,
  11998. -              int warn);  /* for attaching a list of errors */
  11999. -
  12000. -  int err_is_list_attached(int list_num);  /* checking if a list 
  12001. -                                                    is attached */
  12002. -
  12003. -  extern  int err_list_free(int list_num);   /* freeing a list of errors */
  12004. -
  12005. -where list_num is the number of the error list, list_len is the number of
  12006. -errors on the list, err_ptr is the character string explaining the error
  12007. -and warn can be TRUE if this is only a warning (the program continues to
  12008. -run) or it can be FALSE if it is an error (the program stops).
  12009. -
  12010. -The examples are the standard errors (error list 0) and warnings
  12011. -(error list 1) which are in the file err.c
  12012. -
  12013. -
  12014. -                David Stewart and Zbigniew Leyk, 1993
  12015. //GO.SYSIN DD DOC/tutorial.txt
  12016. mkdir MACHINES
  12017. mkdir MACHINES/GCC
  12018. echo MACHINES/GCC/makefile 1>&2
  12019. sed >MACHINES/GCC/makefile <<'//GO.SYSIN DD MACHINES/GCC/makefile' 's/^-//'
  12020. -# 
  12021. -#
  12022. -# Makefile for Meschach for GNU cc
  12023. -#
  12024. -# Copyright (C) David Stewart & Zbigniew Leyk 1993
  12025. -#
  12026. -# $Id: $
  12027. -#
  12028. -
  12029. -srcdir = .
  12030. -VPATH = .
  12031. -
  12032. -CC = gcc
  12033. -
  12034. -DEFS = -DHAVE_CONFIG_H
  12035. -LIBS =  -lm
  12036. -RANLIB = ranlib
  12037. -
  12038. -
  12039. -CFLAGS = -O6
  12040. -
  12041. -
  12042. -.c.o:
  12043. -    $(CC) -c $(CFLAGS) $(DEFS) $<
  12044. -
  12045. -SHELL = /bin/sh
  12046. -MES_PAK = mesch12a
  12047. -TAR = tar
  12048. -SHAR = stree -u
  12049. -ZIP = zip -r -l
  12050. -
  12051. -###############################
  12052. -
  12053. -LIST1 = copy.o err.o matrixio.o memory.o vecop.o matop.o pxop.o \
  12054. -    submat.o init.o otherio.o machine.o matlab.o ivecop.o version.o \
  12055. -    meminfo.o memstat.o
  12056. -LIST2 = lufactor.o bkpfacto.o chfactor.o qrfactor.o solve.o hsehldr.o \
  12057. -    givens.o update.o norm.o hessen.o symmeig.o schur.o svd.o fft.o \
  12058. -    mfunc.o bdfactor.o
  12059. -LIST3 = sparse.o sprow.o sparseio.o spchfctr.o splufctr.o \
  12060. -    spbkp.o spswap.o iter0.o itersym.o iternsym.o
  12061. -ZLIST1 = zmachine.o zcopy.o zmatio.o zmemory.o zvecop.o zmatop.o znorm.o \
  12062. -     zfunc.o 
  12063. -ZLIST2 = zlufctr.o zsolve.o zmatlab.o zhsehldr.o zqrfctr.o \
  12064. -         zgivens.o  zhessen.o zschur.o
  12065. -
  12066. -# they are no longer supported
  12067. -# if you use them add oldpart to all and sparse
  12068. -OLDLIST = conjgrad.o lanczos.o arnoldi.o
  12069. -
  12070. -ALL_LISTS = $(LIST1) $(LIST2) $(LIST3) $(ZLIST1) $(ZLIST2) $(OLDLIST)
  12071. -
  12072. -
  12073. -HLIST = err.h iter.h machine.h matlab.h matrix.h matrix2.h \
  12074. -    meminfo.h oldnames.h sparse.h sparse2.h \
  12075. -    zmatrix.h zmatrix2.h
  12076. -
  12077. -TORTURE = torture.o sptort.o ztorture.o memtort.o itertort.o \
  12078. -     mfuntort.o iotort.o
  12079. -
  12080. -OTHERS = dmacheps.c extras.c fmacheps.c maxint.c  makefile.in \
  12081. -     README configure configure.in machine.h.in copyright \
  12082. -     tutorial.c tutadv.c rk4.dat ls.dat makefile
  12083. -
  12084. -
  12085. -# Different configurations
  12086. -all:  part1 part2 part3 zpart1 zpart2 
  12087. -basic: part1 part2
  12088. -sparse: part1 part2 part3 
  12089. -complex: part1 part2 zpart1 zpart2
  12090. -
  12091. -
  12092. -HBASE = err.h meminfo.h machine.h matrix.h
  12093. -
  12094. -$(LIST1): $(HBASE)
  12095. -part1: $(LIST1)
  12096. -    ar ru meschach.a $(LIST1); $(RANLIB) meschach.a
  12097. -
  12098. -$(LIST2): $(HBASE) matrix2.h
  12099. -part2: $(LIST2)
  12100. -    ar ru meschach.a $(LIST2); $(RANLIB)
  12101. -
  12102. -$(LIST3): $(HBASE) sparse.h sparse2.h
  12103. -part3: $(LIST3)
  12104. -    ar ru meschach.a $(LIST3); $(RANLIB) meschach.a
  12105. -
  12106. -$(ZLIST1): $(HBASDE) zmatrix.h
  12107. -zpart1: $(ZLIST1)
  12108. -    ar ru meschach.a $(ZLIST1); ranlib meschach.a
  12109. -
  12110. -$(ZLIST2): $(HBASE) zmatrix.h zmatrix2.h 
  12111. -zpart2: $(ZLIST2)
  12112. -    ar ru meschach.a $(ZLIST2); ranlib meschach.a
  12113. -
  12114. -$(OLDLIST): $(HBASE) sparse.h sparse2.h 
  12115. -oldpart: $(OLDLIST)
  12116. -    ar ru meschach.a $(OLDLIST); ranlib meschach.a
  12117. -
  12118. -
  12119. -
  12120. -#######################################
  12121. -
  12122. -tar:
  12123. -    - /bin/rm -f $(MES_PAK).tar
  12124. -    chmod 644 `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  12125. -    $(OTHERS) $(HLIST)  `echo $(TORTURE) | sed -e 's/\.o/.c/g'` 
  12126. -    chmod 755 configure
  12127. -    $(TAR) cvf $(MES_PAK).tar \
  12128. -     `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  12129. -    $(HLIST)  $(OTHERS) \
  12130. -    `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  12131. -    MACHINES DOC
  12132. -
  12133. -# use this only for PC machines    
  12134. -msdos-zip:
  12135. -    - /bin/rm -f $(MES_PAK).zip
  12136. -    chmod 644 `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  12137. -    $(OTHERS) $(HLIST) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` 
  12138. -    chmod 755 configure
  12139. -    $(ZIP)  $(MES_PAK).zip \
  12140. -     `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  12141. -    $(HLIST)  $(OTHERS) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  12142. -    MACHINES DOC
  12143. -    
  12144. -
  12145. -fullshar:
  12146. -    - /bin/rm -f $(MES_PAK).shar;
  12147. -    chmod 644 `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  12148. -    $(OTHERS) $(HLIST) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` 
  12149. -    chmod 755 configure
  12150. -    $(SHAR) `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  12151. -    $(HLIST)  $(OTHERS) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  12152. -    MACHINES DOC > $(MES_PAK).shar
  12153. -
  12154. -shar:
  12155. -    - /bin/rm -f meschach1.shar meschach2.shar meschach3.shar \
  12156. -    meschach4.shar oldmeschach.shar meschach0.shar 
  12157. -    chmod 644 `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  12158. -    $(OTHERS) $(HLIST) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` 
  12159. -    chmod 755 configure    
  12160. -    $(SHAR) `echo $(LIST1) | sed -e 's/\.o/.c/g'` > meschach1.shar
  12161. -    $(SHAR) `echo $(LIST2) | sed -e 's/\.o/.c/g'` > meschach2.shar
  12162. -    $(SHAR) `echo $(LIST3) | sed -e 's/\.o/.c/g'` > meschach3.shar    
  12163. -    $(SHAR) `echo $(ZLIST1) | sed -e 's/\.o/.c/g'` \
  12164. -      `echo $(ZLIST2) | sed -e 's/\.o/.c/g'` > meschach4.shar
  12165. -    $(SHAR) `echo $(OLDLIST) | sed -e 's/\.o/.c/g'` > oldmeschach.shar
  12166. -    $(SHAR) $(OTHERS) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  12167. -      $(HLIST)  DOC MACHINES  > meschach0.shar
  12168. -
  12169. -
  12170. -clean:
  12171. -    /bin/rm -f *.o core asx5213a.mat iotort.dat 
  12172. -
  12173. -cleanup:
  12174. -    /bin/rm -f *.o core asx5213a.mat iotort.dat *.a 
  12175. -
  12176. -alltorture: torture sptort ztorture memtort itertort mfuntort iotort
  12177. -
  12178. -torture:torture.o meschach.a
  12179. -    $(CC) $(CFLAGS) $(DEFS) -o torture torture.o \
  12180. -    meschach.a $(LIBS)
  12181. -sptort:sptort.o meschach.a
  12182. -    $(CC) $(CFLAGS) $(DEFS) -o sptort sptort.o \
  12183. -    meschach.a $(LIBS)
  12184. -memtort: memtort.o meschach.a
  12185. -    $(CC) $(CFLAGS) $(DEFS) -o memtort memtort.o \
  12186. -    meschach.a $(LIBS)
  12187. -ztorture:ztorture.o meschach.a
  12188. -    $(CC) $(CFLAGS) $(DEFS) -o ztorture ztorture.o \
  12189. -    meschach.a $(LIBS)
  12190. -itertort: itertort.o meschach.a
  12191. -    $(CC) $(CFLAGS) $(DEFS) -o itertort itertort.o \
  12192. -    meschach.a $(LIBS)
  12193. -
  12194. -iotort: iotort.o meschach.a
  12195. -    $(CC) $(CFLAGS) $(DEFS) -o iotort iotort.o \
  12196. -    meschach.a $(LIBS)
  12197. -mfuntort: mfuntort.o meschach.a
  12198. -    $(CC) $(CFLAGS) $(DEFS) -o mfuntort mfuntort.o \
  12199. -    meschach.a $(LIBS)
  12200. -tstmove: tstmove.o meschach.a
  12201. -    $(CC) $(CFLAGS) $(DEFS) -o tstmove tstmove.o \
  12202. -    meschach.a $(LIBS)
  12203. -tstpxvec: tstpxvec.o meschach.a
  12204. -    $(CC) $(CFLAGS) $(DEFS) -o tstpxvec tstpxvec.o \
  12205. -    meschach.a $(LIBS)
  12206. -
  12207. //GO.SYSIN DD MACHINES/GCC/makefile
  12208. echo MACHINES/GCC/machine.h 1>&2
  12209. sed >MACHINES/GCC/machine.h <<'//GO.SYSIN DD MACHINES/GCC/machine.h' 's/^-//'
  12210. -/* machine.h.  Generated automatically by configure.  */
  12211. -/* Any machine specific stuff goes here */
  12212. -/* Add details necessary for your own installation here! */
  12213. -
  12214. -/* This is for use with "configure" -- if you are not using configure
  12215. -    then use machine.van for the "vanilla" version of machine.h */
  12216. -
  12217. -/* Note special macros: ANSI_C (ANSI C syntax)
  12218. -            SEGMENTED (segmented memory machine e.g. MS-DOS)
  12219. -            MALLOCDECL (declared if malloc() etc have
  12220. -                    been declared) */
  12221. -
  12222. -
  12223. -#define ANSI_C 1
  12224. -#define NOT_SEGMENTED 1
  12225. -/* #undef HAVE_COMPLEX_H */
  12226. -#define HAVE_MALLOC_H 1
  12227. -#define STDC_HEADERS 
  12228. -#define HAVE_BCOPY 1
  12229. -#define HAVE_BZERO 1
  12230. -#define CHAR0ISDBL0 1
  12231. -#define WORDS_BIGENDIAN 1
  12232. -/* #undef U_INT_DEF */
  12233. -
  12234. -
  12235. -/* for basic or larger versions */
  12236. -#define COMPLEX 1
  12237. -#define SPARSE 1
  12238. -
  12239. -/* for loop unrolling */
  12240. -/* #undef VUNROLL */
  12241. -/* #undef MUNROLL */
  12242. -
  12243. -/* for segmented memory */
  12244. -#ifndef NOT_SEGMENTED
  12245. -#define    SEGMENTED
  12246. -#endif
  12247. -
  12248. -/* if the system has malloc.h */
  12249. -#ifdef HAVE_MALLOC_H
  12250. -#define    MALLOCDECL    1
  12251. -#include    <malloc.h>
  12252. -#endif
  12253. -
  12254. -/* any compiler should have this header */
  12255. -/* if not, change it */
  12256. -#include        <stdio.h>
  12257. -
  12258. -
  12259. -/* Check for ANSI C memmove and memset */
  12260. -#ifdef STDC_HEADERS
  12261. -
  12262. -/* standard copy & zero functions */
  12263. -#define    MEM_COPY(from,to,size)    memmove((to),(from),(size))
  12264. -#define    MEM_ZERO(where,size)    memset((where),'\0',(size))
  12265. -
  12266. -#ifndef ANSI_C
  12267. -#define ANSI_C 1
  12268. -#endif
  12269. -
  12270. -#endif
  12271. -
  12272. -/* standard headers */
  12273. -#ifdef ANSI_C
  12274. -#include    <stdlib.h>
  12275. -#include    <stddef.h>
  12276. -#include    <string.h>
  12277. -#include    <float.h>
  12278. -#endif
  12279. -
  12280. -
  12281. -/* if have bcopy & bzero and no alternatives yet known, use them */
  12282. -#ifdef HAVE_BCOPY
  12283. -#ifndef MEM_COPY
  12284. -/* nonstandard copy function */
  12285. -#define    MEM_COPY(from,to,size)    bcopy((char *)(from),(char *)(to),(int)(size))
  12286. -#endif
  12287. -#endif
  12288. -
  12289. -#ifdef HAVE_BZERO
  12290. -#ifndef MEM_ZERO
  12291. -/* nonstandard zero function */
  12292. -#define    MEM_ZERO(where,size)    bzero((char *)(where),(int)(size))
  12293. -#endif
  12294. -#endif
  12295. -
  12296. -/* if the system has complex.h */
  12297. -#ifdef HAVE_COMPLEX_H
  12298. -#include    <complex.h>
  12299. -#endif
  12300. -
  12301. -/* If prototypes are available & ANSI_C not yet defined, then define it,
  12302. -    but don't include any header files as the proper ANSI C headers
  12303. -        aren't here */
  12304. -/* #undef HAVE_PROTOTYPES */
  12305. -#ifdef HAVE_PROTOTYPES
  12306. -#ifndef ANSI_C
  12307. -#define ANSI_C  1
  12308. -#endif
  12309. -#endif
  12310. -
  12311. -/* floating point precision */
  12312. -
  12313. -/* you can choose single, double or long double (if available) precision */
  12314. -
  12315. -#define FLOAT         1
  12316. -#define DOUBLE         2
  12317. -#define LONG_DOUBLE     3
  12318. -
  12319. -/* #undef REAL_FLT */
  12320. -#define REAL_DBL 1
  12321. -
  12322. -/* if nothing is defined, choose double precision */
  12323. -#ifndef REAL_DBL
  12324. -#ifndef REAL_FLT
  12325. -#define REAL_DBL 1
  12326. -#endif
  12327. -#endif
  12328. -
  12329. -/* single precision */
  12330. -#ifdef REAL_FLT
  12331. -#define  Real float
  12332. -#define  LongReal float
  12333. -#define REAL FLOAT
  12334. -#define LONGREAL FLOAT
  12335. -#endif
  12336. -
  12337. -/* double precision */
  12338. -#ifdef REAL_DBL
  12339. -#define Real double
  12340. -#define LongReal double
  12341. -#define REAL DOUBLE
  12342. -#define LONGREAL DOUBLE
  12343. -#endif
  12344. -
  12345. -
  12346. -/* machine epsilon or unit roundoff error */
  12347. -/* This is correct on most IEEE Real precision systems */
  12348. -#ifdef DBL_EPSILON
  12349. -#if REAL == DOUBLE
  12350. -#define    MACHEPS    DBL_EPSILON
  12351. -#elif REAL == FLOAT
  12352. -#define    MACHEPS    FLT_EPSILON
  12353. -#elif REAL == LONGDOUBLE
  12354. -#define MACHEPS LDBL_EPSILON
  12355. -#endif
  12356. -#endif
  12357. -
  12358. -#define F_MACHEPS 1.19209e-07
  12359. -#define D_MACHEPS 2.22045e-16
  12360. -
  12361. -#ifndef MACHEPS
  12362. -#if REAL == DOUBLE
  12363. -#define    MACHEPS    D_MACHEPS
  12364. -#elif REAL == FLOAT  
  12365. -#define MACHEPS F_MACHEPS
  12366. -#elif REAL == LONGDOUBLE
  12367. -#define MACHEPS D_MACHEPS
  12368. -#endif
  12369. -#endif
  12370. -
  12371. -/* #undef M_MACHEPS */
  12372. -
  12373. -/********************
  12374. -#ifdef DBL_EPSILON
  12375. -#define    MACHEPS    DBL_EPSILON
  12376. -#endif
  12377. -#ifdef M_MACHEPS
  12378. -#ifndef MACHEPS
  12379. -#define MACHEPS    M_MACHEPS
  12380. -#endif
  12381. -#endif
  12382. -********************/
  12383. -
  12384. -#define    M_MAX_INT 2147483647
  12385. -#ifdef    M_MAX_INT
  12386. -#ifndef MAX_RAND
  12387. -#define    MAX_RAND ((double)(M_MAX_INT))
  12388. -#endif
  12389. -#endif
  12390. -
  12391. -/* for non-ANSI systems */
  12392. -#ifndef HUGE_VAL
  12393. -#define HUGE_VAL HUGE
  12394. -#endif
  12395. -
  12396. -
  12397. -#ifdef ANSI_C
  12398. -extern    int    isatty(int);
  12399. -#endif
  12400. -
  12401. //GO.SYSIN DD MACHINES/GCC/machine.h
  12402. mkdir MACHINES/RS6000
  12403. echo MACHINES/RS6000/machine.c 1>&2
  12404. sed >MACHINES/RS6000/machine.c <<'//GO.SYSIN DD MACHINES/RS6000/machine.c' 's/^-//'
  12405. -
  12406. -/**************************************************************************
  12407. -**
  12408. -** Copyright (C) 1993 David E. Stewart & Zbigniew Leyk, all rights reserved.
  12409. -**
  12410. -**                 Meschach Library
  12411. -** 
  12412. -** This Meschach Library is provided "as is" without any express 
  12413. -** or implied warranty of any kind with respect to this software. 
  12414. -** In particular the authors shall not be liable for any direct, 
  12415. -** indirect, special, incidental or consequential damages arising 
  12416. -** in any way from use of the software.
  12417. -** 
  12418. -** Everyone is granted permission to copy, modify and redistribute this
  12419. -** Meschach Library, provided:
  12420. -**  1.  All copies contain this copyright notice.
  12421. -**  2.  All modified copies shall carry a notice stating who
  12422. -**      made the last modification and the date of such modification.
  12423. -**  3.  No charge is made for this software or works derived from it.  
  12424. -**      This clause shall not be construed as constraining other software
  12425. -**      distributed on the same medium as this software, nor is a
  12426. -**      distribution fee considered a charge.
  12427. -**
  12428. -***************************************************************************/
  12429. -
  12430. -/*
  12431. -  This file contains basic routines which are used by the functions
  12432. -  in matrix.a etc.
  12433. -  These are the routines that should be modified in order to take
  12434. -  full advantage of specialised architectures (pipelining, vector
  12435. -  processors etc).
  12436. -  */
  12437. -static    char    *rcsid = "$Header: /usr/local/home/des/meschach/meschach/RCS/machine.c,v 1.3 1991/08/29 06:42:11 des Exp $";
  12438. -
  12439. -#include    "machine.h"
  12440. -
  12441. -/* __ip__ -- inner product */
  12442. -double    __ip__(dp1,dp2,len)
  12443. -register double    *dp1, *dp2;
  12444. -int    len;
  12445. -{
  12446. -    register int    len4;
  12447. -    register int    i;
  12448. -    register double    sum0, sum1, sum2, sum3;
  12449. -    
  12450. -    sum0 = sum1 = sum2 = sum3 = 0.0;
  12451. -    
  12452. -    len4 = len / 4;
  12453. -    len  = len % 4;
  12454. -    
  12455. -    for ( i = 0; i < len4; i++ )
  12456. -    {
  12457. -    sum0 += dp1[4*i]*dp2[4*i];
  12458. -    sum1 += dp1[4*i+1]*dp2[4*i+1];
  12459. -    sum2 += dp1[4*i+2]*dp2[4*i+2];
  12460. -    sum3 += dp1[4*i+3]*dp2[4*i+3];
  12461. -    }
  12462. -    sum0 += sum1 + sum2 + sum3;
  12463. -    dp1 += 4*len4;    dp2 += 4*len4;
  12464. -    
  12465. -    for ( i = 0; i < len; i++ )
  12466. -    sum0 += (*dp1++)*(*dp2++);
  12467. -    
  12468. -    return sum0;
  12469. -}
  12470. -
  12471. -/* __mltadd__ -- scalar multiply and add c.f. v_mltadd() */
  12472. -void    __mltadd__(dp1,dp2,s,len)
  12473. -register double    *dp1, *dp2, s;
  12474. -register int    len;
  12475. -{
  12476. -    register int    i, len4;
  12477. -    
  12478. -    len4 = len / 4;
  12479. -    len  = len % 4;
  12480. -    for ( i = 0; i < len4; i++ )
  12481. -    {
  12482. -    dp1[4*i]   += s*dp2[4*i];
  12483. -    dp1[4*i+1] += s*dp2[4*i+1];
  12484. -    dp1[4*i+2] += s*dp2[4*i+2];
  12485. -    dp1[4*i+3] += s*dp2[4*i+3];
  12486. -    }
  12487. -    dp1 += 4*len4;    dp2 += 4*len4;
  12488. -    
  12489. -    for ( i = 0; i < len; i++ )
  12490. -    (*dp1++) += s*(*dp2++);
  12491. -}
  12492. -
  12493. -/* __smlt__ scalar multiply array c.f. sv_mlt() */
  12494. -void    __smlt__(dp,s,out,len)
  12495. -register double    *dp, s, *out;
  12496. -register int    len;
  12497. -{
  12498. -    register int    i;
  12499. -    for ( i = 0; i < len; i++ )
  12500. -    (*out++) = s*(*dp++);
  12501. -}
  12502. -
  12503. -/* __add__ -- add arrays c.f. v_add() */
  12504. -void    __add__(dp1,dp2,out,len)
  12505. -register double    *dp1, *dp2, *out;
  12506. -register int    len;
  12507. -{
  12508. -    register int    i;
  12509. -    for ( i = 0; i < len; i++ )
  12510. -    (*out++) = (*dp1++) + (*dp2++);
  12511. -}
  12512. -
  12513. -/* __sub__ -- subtract arrays c.f. v_sub() */
  12514. -void    __sub__(dp1,dp2,out,len)
  12515. -register double    *dp1, *dp2, *out;
  12516. -register int    len;
  12517. -{
  12518. -    register int    i;
  12519. -    for ( i = 0; i < len; i++ )
  12520. -    (*out++) = (*dp1++) - (*dp2++);
  12521. -}
  12522. -
  12523. -/* __zero__ -- zeros an array of double precision numbers */
  12524. -void    __zero__(dp,len)
  12525. -register double    *dp;
  12526. -register int    len;
  12527. -{
  12528. -    /* if a double precision zero is equivalent to a string of nulls */
  12529. -    MEM_ZERO((char *)dp,len*sizeof(double));
  12530. -    /* else, need to zero the array entry by entry */
  12531. -    /*************************************************
  12532. -      while ( len-- )
  12533. -      *dp++ = 0.0;
  12534. -      *************************************************/
  12535. -}
  12536. -
  12537. -/***********************************************************************
  12538. - ******            Faster versions                ********
  12539. - ***********************************************************************/
  12540. -
  12541. -/* __ip4__ -- compute 4 inner products in one go */
  12542. -void    __ip4__(v0,v1,v2,v3,w,out,len)
  12543. -double    *v0, *v1, *v2, *v3, *w;
  12544. -double    out[4];
  12545. -int    len;
  12546. -{
  12547. -    register int    i, len2;
  12548. -    register double    sum00, sum10, sum20, sum30, w_val0;
  12549. -    register double    sum01, sum11, sum21, sum31, w_val1;
  12550. -    
  12551. -    len2 = len / 2;
  12552. -    len  = len % 2;
  12553. -    sum00 = sum10 = sum20 = sum30 = 0.0;
  12554. -    sum01 = sum11 = sum21 = sum31 = 0.0;
  12555. -    for ( i = 0; i < len2; i++ )
  12556. -    {
  12557. -    w_val0 = w[2*i];
  12558. -    w_val1 = w[2*i+1];
  12559. -    sum00 += v0[2*i]  *w_val0;
  12560. -    sum01 += v0[2*i+1]*w_val1;
  12561. -    sum10 += v1[2*i]  *w_val0;
  12562. -    sum11 += v1[2*i+1]*w_val1;
  12563. -    sum20 += v2[2*i]  *w_val0;
  12564. -    sum21 += v2[2*i+1]*w_val1;
  12565. -    sum30 += v3[2*i]  *w_val0;
  12566. -    sum31 += v3[2*i+1]*w_val1;
  12567. -    }
  12568. -    w += 2*len2;
  12569. -    v0 += 2*len2;
  12570. -    v1 += 2*len2;
  12571. -    v2 += 2*len2;
  12572. -    v3 += 2*len2;
  12573. -    for ( i = 0; i < len; i++ )
  12574. -    {
  12575. -    w_val0 = w[i];
  12576. -    sum00 += v0[i]*w_val0;
  12577. -    sum10 += v1[i]*w_val0;
  12578. -    sum20 += v2[i]*w_val0;
  12579. -    sum30 += v3[i]*w_val0;
  12580. -    }
  12581. -    out[0] = sum00 + sum01;
  12582. -    out[1] = sum10 + sum11;
  12583. -    out[2] = sum20 + sum21;
  12584. -    out[3] = sum30 + sum31;
  12585. -}
  12586. -
  12587. -/* __lc4__ -- linear combinations: w <- w+a[0]*v0+ ... + a[3]*v3 */
  12588. -void    __lc4__(v0,v1,v2,v3,w,a,len)
  12589. -double    *v0, *v1, *v2, *v3, *w;
  12590. -double    a[4];
  12591. -int    len;
  12592. -{
  12593. -    register int    i, len2;
  12594. -    register double    a0, a1, a2, a3, tmp0, tmp1;
  12595. -    
  12596. -    len2 = len / 2;
  12597. -    len  = len % 2;
  12598. -    
  12599. -    a0 = a[0];    a1 = a[1];
  12600. -    a2 = a[2];    a3 = a[3];
  12601. -    for ( i = 0; i < len2; i++ )
  12602. -    {
  12603. -    tmp0 = w[2*i]   + a0*v0[2*i];
  12604. -    tmp1 = w[2*i+1] + a0*v0[2*i+1];
  12605. -    tmp0 += a1*v1[2*i];
  12606. -    tmp1 += a1*v1[2*i+1];
  12607. -    tmp0 += a2*v2[2*i];
  12608. -    tmp1 += a2*v2[2*i+1];
  12609. -    tmp0 += a3*v3[2*i];
  12610. -    tmp1 += a3*v3[2*i+1];
  12611. -    w[2*i]   = tmp0;
  12612. -    w[2*i+1] = tmp1;
  12613. -    }
  12614. -    w += 2*len2;
  12615. -    v0 += 2*len2;
  12616. -    v1 += 2*len2;
  12617. -    v2 += 2*len2;
  12618. -    v3 += 2*len2;
  12619. -    for ( i = 0; i < len; i++ )
  12620. -    w[i] += a0*v0[i] + a1*v1[i] + a2*v2[i] + a3*v3[i];
  12621. -}
  12622. -
  12623. -/* __ma4__ -- multiply and add with 4 vectors: vi <- vi + ai*w */
  12624. -void    __ma4__(v0,v1,v2,v3,w,a,len)
  12625. -double    *v0, *v1, *v2, *v3, *w;
  12626. -double    a[4];
  12627. -int    len;
  12628. -{
  12629. -    register int    i;
  12630. -    register double    a0, a1, a2, a3, w0, w1, w2, w3;
  12631. -
  12632. -    a0 = a[0];    a1 = a[1];
  12633. -    a2 = a[2];    a3 = a[3];
  12634. -    for ( i = 0; i < len; i++ )
  12635. -    {
  12636. -    w0 = w[i];
  12637. -    v0[i] += a0*w0;
  12638. -    v1[i] += a1*w0;
  12639. -    v2[i] += a2*w0;
  12640. -    v3[i] += a3*w0;
  12641. -    }
  12642. -}
  12643. //GO.SYSIN DD MACHINES/RS6000/machine.c
  12644. echo MACHINES/RS6000/machine.h 1>&2
  12645. sed >MACHINES/RS6000/machine.h <<'//GO.SYSIN DD MACHINES/RS6000/machine.h' 's/^-//'
  12646. -
  12647. -/* Note special macros: ANSI_C (ANSI C syntax)
  12648. -            SEGMENTED (segmented memory machine e.g. MS-DOS)
  12649. -            MALLOCDECL (declared if malloc() etc have
  12650. -                    been declared) */
  12651. -
  12652. -#define ANSI_C 1
  12653. -
  12654. -/* #undef MALLOCDECL */
  12655. -#define NOT_SEGMENTED 1
  12656. -/* #undef HAVE_COMPLEX_H */
  12657. -#define HAVE_MALLOC_H 1
  12658. -#define STDC_HEADERS 1
  12659. -#define HAVE_BCOPY 1
  12660. -#define HAVE_BZERO 1
  12661. -#define CHAR0ISDBL0 1
  12662. -#define WORDS_BIGENDIAN 1
  12663. -#define U_INT_DEF 1
  12664. -
  12665. -
  12666. -/* for basic or larger versions */
  12667. -#define COMPLEX 1
  12668. -#define SPARSE 1
  12669. -
  12670. -/* for loop unrolling */
  12671. -/* #undef VUNROLL */
  12672. -/* #undef MUNROLL */
  12673. -
  12674. -/* for segmented memory */
  12675. -#ifndef NOT_SEGMENTED
  12676. -#define    SEGMENTED
  12677. -#endif
  12678. -
  12679. -/* if the system has malloc.h */
  12680. -#ifdef HAVE_MALLOC_H
  12681. -#define    MALLOCDECL    1
  12682. -#include    <malloc.h>
  12683. -#endif
  12684. -
  12685. -/* any compiler should have this header */
  12686. -/* if not, change it */
  12687. -#include        <stdio.h>
  12688. -
  12689. -
  12690. -/* Check for ANSI C memmove and memset */
  12691. -#ifdef STDC_HEADERS
  12692. -
  12693. -/* standard copy & zero functions */
  12694. -#define    MEM_COPY(from,to,size)    memmove((to),(from),(size))
  12695. -#define    MEM_ZERO(where,size)    memset((where),'\0',(size))
  12696. -
  12697. -#ifndef ANSI_C
  12698. -#define ANSI_C 1
  12699. -#endif
  12700. -
  12701. -#endif
  12702. -
  12703. -/* standard headers */
  12704. -#ifdef ANSI_C
  12705. -#include    <stdlib.h>
  12706. -#include    <stddef.h>
  12707. -#include    <string.h>
  12708. -#include    <float.h>
  12709. -#endif
  12710. -
  12711. -
  12712. -/* if have bcopy & bzero and no alternatives yet known, use them */
  12713. -#ifdef HAVE_BCOPY
  12714. -#ifndef MEM_COPY
  12715. -/* nonstandard copy function */
  12716. -#define    MEM_COPY(from,to,size)    bcopy((char *)(from),(char *)(to),(int)(size))
  12717. -#endif
  12718. -#endif
  12719. -
  12720. -#ifdef HAVE_BZERO
  12721. -#ifndef MEM_ZERO
  12722. -/* nonstandard zero function */
  12723. -#define    MEM_ZERO(where,size)    bzero((char *)(where),(int)(size))
  12724. -#endif
  12725. -#endif
  12726. -
  12727. -/* if the system has complex.h */
  12728. -#ifdef HAVE_COMPLEX_H
  12729. -#include    <complex.h>
  12730. -#endif
  12731. -
  12732. -/* If prototypes are available & ANSI_C not yet defined, then define it,
  12733. -    but don't include any header files as the proper ANSI C headers
  12734. -        aren't here */
  12735. -#define HAVE_PROTOTYPES 1
  12736. -#ifdef HAVE_PROTOTYPES
  12737. -#ifndef ANSI_C
  12738. -#define ANSI_C  1
  12739. -#endif
  12740. -#endif
  12741. -
  12742. -/* floating point precision */
  12743. -
  12744. -/* you can choose single, double or long double (if available) precision */
  12745. -
  12746. -#define FLOAT         1
  12747. -#define DOUBLE         2
  12748. -#define LONG_DOUBLE     3
  12749. -
  12750. -/* #undef REAL_FLT */
  12751. -/* #undef REAL_DBL */
  12752. -
  12753. -/* if nothing is defined, choose double precision */
  12754. -#ifndef REAL_DBL
  12755. -#ifndef REAL_FLT
  12756. -#define REAL_DBL 1
  12757. -#endif
  12758. -#endif
  12759. -
  12760. -/* single precision */
  12761. -#ifdef REAL_FLT
  12762. -#define  Real float
  12763. -#define  LongReal float
  12764. -#define REAL FLOAT
  12765. -#define LONGREAL FLOAT
  12766. -#endif
  12767. -
  12768. -/* double precision */
  12769. -#ifdef REAL_DBL
  12770. -#define Real double
  12771. -#define LongReal double
  12772. -#define REAL DOUBLE
  12773. -#define LONGREAL DOUBLE
  12774. -#endif
  12775. -
  12776. -
  12777. -/* machine epsilon or unit roundoff error */
  12778. -/* This is correct on most IEEE Real precision systems */
  12779. -#ifdef DBL_EPSILON
  12780. -#if REAL == DOUBLE
  12781. -#define    MACHEPS    DBL_EPSILON
  12782. -#elif REAL == FLOAT
  12783. -#define    MACHEPS    FLT_EPSILON
  12784. -#elif REAL == LONGDOUBLE
  12785. -#define MACHEPS LDBL_EPSILON
  12786. -#endif
  12787. -#endif
  12788. -
  12789. -#define F_MACHEPS 1.19209e-07
  12790. -#define D_MACHEPS 2.22045e-16
  12791. -
  12792. -#ifndef MACHEPS
  12793. -#if REAL == DOUBLE
  12794. -#define    MACHEPS    D_MACHEPS
  12795. -#elif REAL == FLOAT  
  12796. -#define MACHEPS F_MACHEPS
  12797. -#elif REAL == LONGDOUBLE
  12798. -#define MACHEPS D_MACHEPS
  12799. -#endif
  12800. -#endif
  12801. -
  12802. -/* #undef M_MACHEPS */
  12803. -
  12804. -/********************
  12805. -#ifdef DBL_EPSILON
  12806. -#define    MACHEPS    DBL_EPSILON
  12807. -#endif
  12808. -#ifdef M_MACHEPS
  12809. -#ifndef MACHEPS
  12810. -#define MACHEPS    M_MACHEPS
  12811. -#endif
  12812. -#endif
  12813. -********************/
  12814. -
  12815. -#define    M_MAX_INT 2147483647
  12816. -#ifdef    M_MAX_INT
  12817. -#ifndef MAX_RAND
  12818. -#define    MAX_RAND ((double)(M_MAX_INT))
  12819. -#endif
  12820. -#endif
  12821. -
  12822. -/* for non-ANSI systems */
  12823. -#ifndef HUGE_VAL
  12824. -#define HUGE_VAL HUGE
  12825. -#endif
  12826. -
  12827. -
  12828. -#ifdef ANSI_C
  12829. -extern    int    isatty(int);
  12830. -#endif
  12831. -
  12832. //GO.SYSIN DD MACHINES/RS6000/machine.h
  12833. echo MACHINES/RS6000/makefile 1>&2
  12834. sed >MACHINES/RS6000/makefile <<'//GO.SYSIN DD MACHINES/RS6000/makefile' 's/^-//'
  12835. -# Generated automatically from makefile.in by configure.
  12836. -#
  12837. -# Makefile for Meschach via autoconf
  12838. -#
  12839. -# Copyright (C) David Stewart & Zbigniew Leyk 1993
  12840. -#
  12841. -# $Id: $
  12842. -#
  12843. -
  12844. -srcdir = .
  12845. -VPATH = .
  12846. -
  12847. -CC = cc
  12848. -
  12849. -DEFS = -DHAVE_CONFIG_H
  12850. -LIBS =  -lm
  12851. -RANLIB = ranlib
  12852. -
  12853. -
  12854. -CFLAGS = -O
  12855. -
  12856. -
  12857. -.c.o:
  12858. -    $(CC) -c $(CFLAGS) $(DEFS) $<
  12859. -
  12860. -SHELL = /bin/sh
  12861. -MES_PAK = mesch12a
  12862. -TAR = tar
  12863. -SHAR = stree -u
  12864. -ZIP = zip -r -l
  12865. -FLIST = FILELIST
  12866. -
  12867. -###############################
  12868. -
  12869. -LIST1 = copy.o err.o matrixio.o memory.o vecop.o matop.o pxop.o \
  12870. -    submat.o init.o otherio.o machine.o matlab.o ivecop.o version.o \
  12871. -    meminfo.o memstat.o
  12872. -LIST2 = lufactor.o bkpfacto.o chfactor.o qrfactor.o solve.o hsehldr.o \
  12873. -    givens.o update.o norm.o hessen.o symmeig.o schur.o svd.o fft.o \
  12874. -    mfunc.o bdfactor.o
  12875. -LIST3 = sparse.o sprow.o sparseio.o spchfctr.o splufctr.o \
  12876. -    spbkp.o spswap.o iter0.o itersym.o iternsym.o
  12877. -ZLIST1 = zmachine.o zcopy.o zmatio.o zmemory.o zvecop.o zmatop.o znorm.o \
  12878. -     zfunc.o 
  12879. -ZLIST2 = zlufctr.o zsolve.o zmatlab.o zhsehldr.o zqrfctr.o \
  12880. -         zgivens.o  zhessen.o zschur.o
  12881. -
  12882. -# they are no longer supported
  12883. -# if you use them add oldpart to all and sparse
  12884. -OLDLIST = conjgrad.o lanczos.o arnoldi.o
  12885. -
  12886. -ALL_LISTS = $(LIST1) $(LIST2) $(LIST3) $(ZLIST1) $(ZLIST2) $(OLDLIST)
  12887. -
  12888. -HBASE = err.h meminfo.h machine.h matrix.h
  12889. -
  12890. -HLIST = $(HBASE) iter.h matlab.h matrix2.h  oldnames.h sparse.h \
  12891. -    sparse2.h  zmatrix.h zmatrix2.h
  12892. -
  12893. -TORTURE = torture.o sptort.o ztorture.o memtort.o itertort.o \
  12894. -     mfuntort.o iotort.o
  12895. -
  12896. -OTHERS = dmacheps.c extras.c fmacheps.c maxint.c  makefile.in \
  12897. -     README configure configure.in machine.h.in copyright \
  12898. -     tutorial.c tutadv.c rk4.dat ls.dat makefile $(FLIST)
  12899. -
  12900. -
  12901. -# Different configurations
  12902. -all:  part1 part2 part3 zpart1 zpart2 
  12903. -basic: part1 part2
  12904. -sparse: part1 part2 part3 
  12905. -complex: part1 part2 zpart1 zpart2
  12906. -
  12907. -
  12908. -$(LIST1): $(HBASE)
  12909. -part1: $(LIST1)
  12910. -    ar ru meschach.a $(LIST1); $(RANLIB) meschach.a
  12911. -
  12912. -$(LIST2): $(HBASE) matrix2.h
  12913. -part2: $(LIST2)
  12914. -    ar ru meschach.a $(LIST2); $(RANLIB) meschach.a
  12915. -schur.o: schur.c $(HBASE) matrix2.h
  12916. -    cc -c $(DEFS) schur.c
  12917. -
  12918. -$(LIST3): $(HBASE) sparse.h sparse2.h
  12919. -part3: $(LIST3)
  12920. -    ar ru meschach.a $(LIST3); $(RANLIB) meschach.a
  12921. -
  12922. -$(ZLIST1): $(HBASDE) zmatrix.h
  12923. -zpart1: $(ZLIST1)
  12924. -    ar ru meschach.a $(ZLIST1); ranlib meschach.a
  12925. -
  12926. -$(ZLIST2): $(HBASE) zmatrix.h zmatrix2.h 
  12927. -zpart2: $(ZLIST2)
  12928. -    ar ru meschach.a $(ZLIST2); ranlib meschach.a
  12929. -
  12930. -$(OLDLIST): $(HBASE) sparse.h sparse2.h 
  12931. -oldpart: $(OLDLIST)
  12932. -    ar ru meschach.a $(OLDLIST); ranlib meschach.a
  12933. -
  12934. -
  12935. -
  12936. -#######################################
  12937. -
  12938. -tar:
  12939. -    - /bin/rm -f $(MES_PAK).tar
  12940. -    chmod 644 `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  12941. -    $(OTHERS) $(HLIST)  `echo $(TORTURE) | sed -e 's/\.o/.c/g'` 
  12942. -    chmod 755 configure
  12943. -    $(MAKE) list
  12944. -    $(TAR) cvf $(MES_PAK).tar \
  12945. -     `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  12946. -    $(HLIST)  $(OTHERS) \
  12947. -    `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  12948. -    MACHINES DOC
  12949. -
  12950. -# use this only for PC machines    
  12951. -msdos-zip:
  12952. -    - /bin/rm -f $(MES_PAK).zip
  12953. -    chmod 644 `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  12954. -    $(OTHERS) $(HLIST) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` 
  12955. -    chmod 755 configure
  12956. -    $(MAKE) list
  12957. -    $(ZIP)  $(MES_PAK).zip \
  12958. -     `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  12959. -    $(HLIST)  $(OTHERS) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  12960. -    MACHINES DOC
  12961. -    
  12962. -
  12963. -fullshar:
  12964. -    - /bin/rm -f $(MES_PAK).shar;
  12965. -    chmod 644 `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  12966. -    $(OTHERS) $(HLIST) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` 
  12967. -    chmod 755 configure
  12968. -    $(MAKE) list
  12969. -    $(SHAR) `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  12970. -    $(HLIST)  $(OTHERS) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  12971. -    MACHINES DOC > $(MES_PAK).shar
  12972. -
  12973. -shar:
  12974. -    - /bin/rm -f meschach1.shar meschach2.shar meschach3.shar \
  12975. -    meschach4.shar oldmeschach.shar meschach0.shar 
  12976. -    chmod 644 `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  12977. -    $(OTHERS) $(HLIST) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` 
  12978. -    chmod 755 configure    
  12979. -    $(MAKE) list
  12980. -    $(SHAR) `echo $(LIST1) | sed -e 's/\.o/.c/g'` > meschach1.shar
  12981. -    $(SHAR) `echo $(LIST2) | sed -e 's/\.o/.c/g'` > meschach2.shar
  12982. -    $(SHAR) `echo $(LIST3) | sed -e 's/\.o/.c/g'` > meschach3.shar    
  12983. -    $(SHAR) `echo $(ZLIST1) | sed -e 's/\.o/.c/g'` \
  12984. -      `echo $(ZLIST2) | sed -e 's/\.o/.c/g'` > meschach4.shar
  12985. -    $(SHAR) `echo $(OLDLIST) | sed -e 's/\.o/.c/g'` > oldmeschach.shar
  12986. -    $(SHAR) $(OTHERS) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  12987. -      $(HLIST)  DOC MACHINES  > meschach0.shar
  12988. -
  12989. -list:
  12990. -    /bin/rm -f $(FLIST)
  12991. -    ls -lR `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  12992. -    `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  12993. -    $(HLIST) $(OTHERS) MACHINES DOC \
  12994. -    |awk '/^$$/ {print};/^[-d]/ {printf("%s %s   %10d %s %s %s %s\n", \
  12995. -     $$1,$$2,$$5,$$6,$$7,$$8,$$9)}; /^[^-d]/ {print}' \
  12996. -    > $(FLIST)
  12997. -
  12998. -
  12999. -
  13000. -clean:
  13001. -    /bin/rm -f *.o core asx5213a.mat iotort.dat 
  13002. -
  13003. -cleanup:
  13004. -    /bin/rm -f *.o core asx5213a.mat iotort.dat *.a 
  13005. -
  13006. -alltorture: torture sptort ztorture memtort itertort mfuntort iotort
  13007. -
  13008. -torture:torture.o meschach.a
  13009. -    $(CC) $(CFLAGS) $(DEFS) -o torture torture.o \
  13010. -    meschach.a $(LIBS)
  13011. -sptort:sptort.o meschach.a
  13012. -    $(CC) $(CFLAGS) $(DEFS) -o sptort sptort.o \
  13013. -    meschach.a $(LIBS)
  13014. -memtort: memtort.o meschach.a
  13015. -    $(CC) $(CFLAGS) $(DEFS) -o memtort memtort.o \
  13016. -    meschach.a $(LIBS)
  13017. -ztorture:ztorture.o meschach.a
  13018. -    $(CC) $(CFLAGS) $(DEFS) -o ztorture ztorture.o \
  13019. -    meschach.a $(LIBS)
  13020. -itertort: itertort.o meschach.a
  13021. -    $(CC) $(CFLAGS) $(DEFS) -o itertort itertort.o \
  13022. -    meschach.a $(LIBS)
  13023. -
  13024. -iotort: iotort.o meschach.a
  13025. -    $(CC) $(CFLAGS) $(DEFS) -o iotort iotort.o \
  13026. -    meschach.a $(LIBS)
  13027. -mfuntort: mfuntort.o meschach.a
  13028. -    $(CC) $(CFLAGS) $(DEFS) -o mfuntort mfuntort.o \
  13029. -    meschach.a $(LIBS)
  13030. -tstmove: tstmove.o meschach.a
  13031. -    $(CC) $(CFLAGS) $(DEFS) -o tstmove tstmove.o \
  13032. -    meschach.a $(LIBS)
  13033. -tstpxvec: tstpxvec.o meschach.a
  13034. -    $(CC) $(CFLAGS) $(DEFS) -o tstpxvec tstpxvec.o \
  13035. -    meschach.a $(LIBS)
  13036. -
  13037. //GO.SYSIN DD MACHINES/RS6000/makefile
  13038. mkdir MACHINES/SPARC
  13039. echo MACHINES/SPARC/machine.h 1>&2
  13040. sed >MACHINES/SPARC/machine.h <<'//GO.SYSIN DD MACHINES/SPARC/machine.h' 's/^-//'
  13041. -
  13042. -/* Note special macros: ANSI_C (ANSI C syntax)
  13043. -            SEGMENTED (segmented memory machine e.g. MS-DOS)
  13044. -            MALLOCDECL (declared if malloc() etc have
  13045. -                    been declared) */
  13046. -
  13047. -#define const 
  13048. -
  13049. -/* #undef MALLOCDECL */
  13050. -#define NOT_SEGMENTED 1
  13051. -/* #undef HAVE_COMPLEX_H */
  13052. -#define HAVE_MALLOC_H 1
  13053. -/* #undef STDC_HEADERS */
  13054. -#define HAVE_BCOPY 1
  13055. -#define HAVE_BZERO 1
  13056. -#define CHAR0ISDBL0 1
  13057. -#define WORDS_BIGENDIAN 1
  13058. -/* #undef U_INT_DEF */
  13059. -#define VARARGS 1
  13060. -
  13061. -
  13062. -/* for basic or larger versions */
  13063. -#define COMPLEX 1
  13064. -#define SPARSE 1
  13065. -
  13066. -/* for loop unrolling */
  13067. -/* #undef VUNROLL */
  13068. -/* #undef MUNROLL */
  13069. -
  13070. -/* for segmented memory */
  13071. -#ifndef NOT_SEGMENTED
  13072. -#define    SEGMENTED
  13073. -#endif
  13074. -
  13075. -/* if the system has malloc.h */
  13076. -#ifdef HAVE_MALLOC_H
  13077. -#define    MALLOCDECL    1
  13078. -#include    <malloc.h>
  13079. -#endif
  13080. -
  13081. -/* any compiler should have this header */
  13082. -/* if not, change it */
  13083. -#include        <stdio.h>
  13084. -
  13085. -
  13086. -/* Check for ANSI C memmove and memset */
  13087. -#ifdef STDC_HEADERS
  13088. -
  13089. -/* standard copy & zero functions */
  13090. -#define    MEM_COPY(from,to,size)    memmove((to),(from),(size))
  13091. -#define    MEM_ZERO(where,size)    memset((where),'\0',(size))
  13092. -
  13093. -#ifndef ANSI_C
  13094. -#define ANSI_C 1
  13095. -#endif
  13096. -
  13097. -#endif
  13098. -
  13099. -/* standard headers */
  13100. -#ifdef ANSI_C
  13101. -#include    <stdlib.h>
  13102. -#include    <stddef.h>
  13103. -#include    <string.h>
  13104. -#include    <float.h>
  13105. -#endif
  13106. -
  13107. -
  13108. -/* if have bcopy & bzero and no alternatives yet known, use them */
  13109. -#ifdef HAVE_BCOPY
  13110. -#ifndef MEM_COPY
  13111. -/* nonstandard copy function */
  13112. -#define    MEM_COPY(from,to,size)    bcopy((char *)(from),(char *)(to),(int)(size))
  13113. -#endif
  13114. -#endif
  13115. -
  13116. -#ifdef HAVE_BZERO
  13117. -#ifndef MEM_ZERO
  13118. -/* nonstandard zero function */
  13119. -#define    MEM_ZERO(where,size)    bzero((char *)(where),(int)(size))
  13120. -#endif
  13121. -#endif
  13122. -
  13123. -/* if the system has complex.h */
  13124. -#ifdef HAVE_COMPLEX_H
  13125. -#include    <complex.h>
  13126. -#endif
  13127. -
  13128. -/* If prototypes are available & ANSI_C not yet defined, then define it,
  13129. -    but don't include any header files as the proper ANSI C headers
  13130. -        aren't here */
  13131. -/* #undef HAVE_PROTOTYPES */
  13132. -#ifdef HAVE_PROTOTYPES
  13133. -#ifndef ANSI_C
  13134. -#define ANSI_C  1
  13135. -#endif
  13136. -#endif
  13137. -
  13138. -/* floating point precision */
  13139. -
  13140. -/* you can choose single, double or long double (if available) precision */
  13141. -
  13142. -#define FLOAT         1
  13143. -#define DOUBLE         2
  13144. -#define LONG_DOUBLE     3
  13145. -
  13146. -/* #undef REAL_FLT */
  13147. -#define REAL_DBL 1
  13148. -
  13149. -/* if nothing is defined, choose double precision */
  13150. -#ifndef REAL_DBL
  13151. -#ifndef REAL_FLT
  13152. -#define REAL_DBL 1
  13153. -#endif
  13154. -#endif
  13155. -
  13156. -/* single precision */
  13157. -#ifdef REAL_FLT
  13158. -#define  Real float
  13159. -#define  LongReal float
  13160. -#define REAL FLOAT
  13161. -#define LONGREAL FLOAT
  13162. -#endif
  13163. -
  13164. -/* double precision */
  13165. -#ifdef REAL_DBL
  13166. -#define Real double
  13167. -#define LongReal double
  13168. -#define REAL DOUBLE
  13169. -#define LONGREAL DOUBLE
  13170. -#endif
  13171. -
  13172. -
  13173. -/* machine epsilon or unit roundoff error */
  13174. -/* This is correct on most IEEE Real precision systems */
  13175. -#ifdef DBL_EPSILON
  13176. -#if REAL == DOUBLE
  13177. -#define    MACHEPS    DBL_EPSILON
  13178. -#elif REAL == FLOAT
  13179. -#define    MACHEPS    FLT_EPSILON
  13180. -#elif REAL == LONGDOUBLE
  13181. -#define MACHEPS LDBL_EPSILON
  13182. -#endif
  13183. -#endif
  13184. -
  13185. -#define F_MACHEPS 1.19209e-07
  13186. -#define D_MACHEPS 2.22045e-16
  13187. -
  13188. -#ifndef MACHEPS
  13189. -#if REAL == DOUBLE
  13190. -#define    MACHEPS    D_MACHEPS
  13191. -#elif REAL == FLOAT  
  13192. -#define MACHEPS F_MACHEPS
  13193. -#elif REAL == LONGDOUBLE
  13194. -#define MACHEPS D_MACHEPS
  13195. -#endif
  13196. -#endif
  13197. -
  13198. -/* #undef M_MACHEPS */
  13199. -
  13200. -/********************
  13201. -#ifdef DBL_EPSILON
  13202. -#define    MACHEPS    DBL_EPSILON
  13203. -#endif
  13204. -#ifdef M_MACHEPS
  13205. -#ifndef MACHEPS
  13206. -#define MACHEPS    M_MACHEPS
  13207. -#endif
  13208. -#endif
  13209. -********************/
  13210. -
  13211. -#define    M_MAX_INT 2147483647
  13212. -#ifdef    M_MAX_INT
  13213. -#ifndef MAX_RAND
  13214. -#define    MAX_RAND ((double)(M_MAX_INT))
  13215. -#endif
  13216. -#endif
  13217. -
  13218. -/* for non-ANSI systems */
  13219. -#ifndef HUGE_VAL
  13220. -#define HUGE_VAL HUGE
  13221. -#endif
  13222. -
  13223. -
  13224. -#ifdef ANSI_C
  13225. -extern    int    isatty(int);
  13226. -#endif
  13227. -
  13228. //GO.SYSIN DD MACHINES/SPARC/machine.h
  13229. echo MACHINES/SPARC/makefile 1>&2
  13230. sed >MACHINES/SPARC/makefile <<'//GO.SYSIN DD MACHINES/SPARC/makefile' 's/^-//'
  13231. -# #
  13232. -# Makefile for Meschach for SUN SPARC cc
  13233. -#
  13234. -# Copyright (C) David Stewart & Zbigniew Leyk 1993
  13235. -#
  13236. -# $Id: $
  13237. -#
  13238. -
  13239. -srcdir = .
  13240. -VPATH = .
  13241. -
  13242. -CC = cc
  13243. -
  13244. -DEFS = -DHAVE_CONFIG_H
  13245. -LIBS =  -lm
  13246. -RANLIB = ranlib
  13247. -
  13248. -
  13249. -CFLAGS = -O
  13250. -
  13251. -
  13252. -.c.o:
  13253. -    $(CC) -c $(CFLAGS) $(DEFS) $<
  13254. -
  13255. -SHELL = /bin/sh
  13256. -MES_PAK = mesch12a
  13257. -TAR = tar
  13258. -SHAR = stree -u
  13259. -ZIP = zip -r -l
  13260. -
  13261. -###############################
  13262. -
  13263. -LIST1 = copy.o err.o matrixio.o memory.o vecop.o matop.o pxop.o \
  13264. -    submat.o init.o otherio.o machine.o matlab.o ivecop.o version.o \
  13265. -    meminfo.o memstat.o
  13266. -LIST2 = lufactor.o bkpfacto.o chfactor.o qrfactor.o solve.o hsehldr.o \
  13267. -    givens.o update.o norm.o hessen.o symmeig.o schur.o svd.o fft.o \
  13268. -    mfunc.o bdfactor.o
  13269. -LIST3 = sparse.o sprow.o sparseio.o spchfctr.o splufctr.o \
  13270. -    spbkp.o spswap.o iter0.o itersym.o iternsym.o
  13271. -ZLIST1 = zmachine.o zcopy.o zmatio.o zmemory.o zvecop.o zmatop.o znorm.o \
  13272. -     zfunc.o 
  13273. -ZLIST2 = zlufctr.o zsolve.o zmatlab.o zhsehldr.o zqrfctr.o \
  13274. -         zgivens.o  zhessen.o zschur.o
  13275. -
  13276. -# they are no longer supported
  13277. -# if you use them add oldpart to all and sparse
  13278. -OLDLIST = conjgrad.o lanczos.o arnoldi.o
  13279. -
  13280. -ALL_LISTS = $(LIST1) $(LIST2) $(LIST3) $(ZLIST1) $(ZLIST2) $(OLDLIST)
  13281. -
  13282. -
  13283. -HLIST = err.h iter.h machine.h matlab.h matrix.h matrix2.h \
  13284. -    meminfo.h oldnames.h sparse.h sparse2.h \
  13285. -    zmatrix.h zmatrix2.h
  13286. -
  13287. -TORTURE = torture.o sptort.o ztorture.o memtort.o itertort.o \
  13288. -     mfuntort.o iotort.o
  13289. -
  13290. -OTHERS = dmacheps.c extras.c fmacheps.c maxint.c  makefile.in \
  13291. -     README configure configure.in machine.h.in copyright \
  13292. -     tutorial.c tutadv.c rk4.dat ls.dat makefile
  13293. -
  13294. -
  13295. -# Different configurations
  13296. -all:  part1 part2 part3 zpart1 zpart2 
  13297. -basic: part1 part2
  13298. -sparse: part1 part2 part3 
  13299. -complex: part1 part2 zpart1 zpart2
  13300. -
  13301. -
  13302. -HBASE = err.h meminfo.h machine.h matrix.h
  13303. -
  13304. -$(LIST1): $(HBASE)
  13305. -part1: $(LIST1)
  13306. -    ar ru meschach.a $(LIST1); $(RANLIB) meschach.a
  13307. -
  13308. -$(LIST2): $(HBASE) matrix2.h
  13309. -part2: $(LIST2)
  13310. -    ar ru meschach.a $(LIST2); $(RANLIB)
  13311. -
  13312. -$(LIST3): $(HBASE) sparse.h sparse2.h
  13313. -part3: $(LIST3)
  13314. -    ar ru meschach.a $(LIST3); $(RANLIB) meschach.a
  13315. -
  13316. -$(ZLIST1): $(HBASDE) zmatrix.h
  13317. -zpart1: $(ZLIST1)
  13318. -    ar ru meschach.a $(ZLIST1); ranlib meschach.a
  13319. -
  13320. -$(ZLIST2): $(HBASE) zmatrix.h zmatrix2.h 
  13321. -zpart2: $(ZLIST2)
  13322. -    ar ru meschach.a $(ZLIST2); ranlib meschach.a
  13323. -
  13324. -$(OLDLIST): $(HBASE) sparse.h sparse2.h 
  13325. -oldpart: $(OLDLIST)
  13326. -    ar ru meschach.a $(OLDLIST); ranlib meschach.a
  13327. -
  13328. -
  13329. -
  13330. -#######################################
  13331. -
  13332. -tar:
  13333. -    - /bin/rm -f $(MES_PAK).tar
  13334. -    chmod 644 `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  13335. -    $(OTHERS) $(HLIST)  `echo $(TORTURE) | sed -e 's/\.o/.c/g'` 
  13336. -    chmod 755 configure
  13337. -    $(TAR) cvf $(MES_PAK).tar \
  13338. -     `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  13339. -    $(HLIST)  $(OTHERS) \
  13340. -    `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  13341. -    MACHINES DOC
  13342. -
  13343. -# use this only for PC machines    
  13344. -msdos-zip:
  13345. -    - /bin/rm -f $(MES_PAK).zip
  13346. -    chmod 644 `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  13347. -    $(OTHERS) $(HLIST) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` 
  13348. -    chmod 755 configure
  13349. -    $(ZIP)  $(MES_PAK).zip \
  13350. -     `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  13351. -    $(HLIST)  $(OTHERS) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  13352. -    MACHINES DOC
  13353. -    
  13354. -
  13355. -fullshar:
  13356. -    - /bin/rm -f $(MES_PAK).shar;
  13357. -    chmod 644 `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  13358. -    $(OTHERS) $(HLIST) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` 
  13359. -    chmod 755 configure
  13360. -    $(SHAR) `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  13361. -    $(HLIST)  $(OTHERS) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  13362. -    MACHINES DOC > $(MES_PAK).shar
  13363. -
  13364. -shar:
  13365. -    - /bin/rm -f meschach1.shar meschach2.shar meschach3.shar \
  13366. -    meschach4.shar oldmeschach.shar meschach0.shar 
  13367. -    chmod 644 `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  13368. -    $(OTHERS) $(HLIST) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` 
  13369. -    chmod 755 configure    
  13370. -    $(SHAR) `echo $(LIST1) | sed -e 's/\.o/.c/g'` > meschach1.shar
  13371. -    $(SHAR) `echo $(LIST2) | sed -e 's/\.o/.c/g'` > meschach2.shar
  13372. -    $(SHAR) `echo $(LIST3) | sed -e 's/\.o/.c/g'` > meschach3.shar    
  13373. -    $(SHAR) `echo $(ZLIST1) | sed -e 's/\.o/.c/g'` \
  13374. -      `echo $(ZLIST2) | sed -e 's/\.o/.c/g'` > meschach4.shar
  13375. -    $(SHAR) `echo $(OLDLIST) | sed -e 's/\.o/.c/g'` > oldmeschach.shar
  13376. -    $(SHAR) $(OTHERS) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  13377. -      $(HLIST)  DOC MACHINES  > meschach0.shar
  13378. -
  13379. -
  13380. -clean:
  13381. -    /bin/rm -f *.o core asx5213a.mat iotort.dat 
  13382. -
  13383. -cleanup:
  13384. -    /bin/rm -f *.o core asx5213a.mat iotort.dat *.a 
  13385. -
  13386. -alltorture: torture sptort ztorture memtort itertort mfuntort iotort
  13387. -
  13388. -torture:torture.o meschach.a
  13389. -    $(CC) $(CFLAGS) $(DEFS) -o torture torture.o \
  13390. -    meschach.a $(LIBS)
  13391. -sptort:sptort.o meschach.a
  13392. -    $(CC) $(CFLAGS) $(DEFS) -o sptort sptort.o \
  13393. -    meschach.a $(LIBS)
  13394. -memtort: memtort.o meschach.a
  13395. -    $(CC) $(CFLAGS) $(DEFS) -o memtort memtort.o \
  13396. -    meschach.a $(LIBS)
  13397. -ztorture:ztorture.o meschach.a
  13398. -    $(CC) $(CFLAGS) $(DEFS) -o ztorture ztorture.o \
  13399. -    meschach.a $(LIBS)
  13400. -itertort: itertort.o meschach.a
  13401. -    $(CC) $(CFLAGS) $(DEFS) -o itertort itertort.o \
  13402. -    meschach.a $(LIBS)
  13403. -
  13404. -iotort: iotort.o meschach.a
  13405. -    $(CC) $(CFLAGS) $(DEFS) -o iotort iotort.o \
  13406. -    meschach.a $(LIBS)
  13407. -mfuntort: mfuntort.o meschach.a
  13408. -    $(CC) $(CFLAGS) $(DEFS) -o mfuntort mfuntort.o \
  13409. -    meschach.a $(LIBS)
  13410. -tstmove: tstmove.o meschach.a
  13411. -    $(CC) $(CFLAGS) $(DEFS) -o tstmove tstmove.o \
  13412. -    meschach.a $(LIBS)
  13413. -tstpxvec: tstpxvec.o meschach.a
  13414. -    $(CC) $(CFLAGS) $(DEFS) -o tstpxvec tstpxvec.o \
  13415. -    meschach.a $(LIBS)
  13416. -
  13417. //GO.SYSIN DD MACHINES/SPARC/makefile
  13418. mkdir MACHINES/Linux
  13419. echo MACHINES/Linux/makefile 1>&2
  13420. sed >MACHINES/Linux/makefile <<'//GO.SYSIN DD MACHINES/Linux/makefile' 's/^-//'
  13421. -# Generated automatically from makefile.in by configure.
  13422. -#
  13423. -# Makefile for Meschach via autoconf
  13424. -#
  13425. -# Copyright (C) David Stewart & Zbigniew Leyk 1993
  13426. -#
  13427. -# $Id: $
  13428. -#
  13429. -
  13430. -srcdir = .
  13431. -VPATH = .
  13432. -
  13433. -CC = cc
  13434. -
  13435. -DEFS = -DHAVE_CONFIG_H
  13436. -LIBS =  -lm
  13437. -RANLIB = ranlib
  13438. -
  13439. -
  13440. -CFLAGS = -O
  13441. -
  13442. -
  13443. -.c.o:
  13444. -    $(CC) -c $(CFLAGS) $(DEFS) $<
  13445. -
  13446. -SHELL = /bin/sh
  13447. -MES_PAK = mesch12a
  13448. -TAR = tar
  13449. -SHAR = stree -u
  13450. -ZIP = zip -r -l
  13451. -FLIST = FILELIST
  13452. -
  13453. -###############################
  13454. -
  13455. -LIST1 = copy.o err.o matrixio.o memory.o vecop.o matop.o pxop.o \
  13456. -    submat.o init.o otherio.o machine.o matlab.o ivecop.o version.o \
  13457. -    meminfo.o memstat.o
  13458. -LIST2 = lufactor.o bkpfacto.o chfactor.o qrfactor.o solve.o hsehldr.o \
  13459. -    givens.o update.o norm.o hessen.o symmeig.o schur.o svd.o fft.o \
  13460. -    mfunc.o bdfactor.o
  13461. -LIST3 = sparse.o sprow.o sparseio.o spchfctr.o splufctr.o \
  13462. -    spbkp.o spswap.o iter0.o itersym.o iternsym.o
  13463. -ZLIST1 = zmachine.o zcopy.o zmatio.o zmemory.o zvecop.o zmatop.o znorm.o \
  13464. -     zfunc.o 
  13465. -ZLIST2 = zlufctr.o zsolve.o zmatlab.o zhsehldr.o zqrfctr.o \
  13466. -         zgivens.o  zhessen.o zschur.o
  13467. -
  13468. -# they are no longer supported
  13469. -# if you use them add oldpart to all and sparse
  13470. -OLDLIST = conjgrad.o lanczos.o arnoldi.o
  13471. -
  13472. -ALL_LISTS = $(LIST1) $(LIST2) $(LIST3) $(ZLIST1) $(ZLIST2) $(OLDLIST)
  13473. -
  13474. -HBASE = err.h meminfo.h machine.h matrix.h
  13475. -
  13476. -HLIST = $(HBASE) iter.h matlab.h matrix2.h  oldnames.h sparse.h \
  13477. -    sparse2.h  zmatrix.h zmatrix2.h
  13478. -
  13479. -TORTURE = torture.o sptort.o ztorture.o memtort.o itertort.o \
  13480. -     mfuntort.o iotort.o
  13481. -
  13482. -OTHERS = dmacheps.c extras.c fmacheps.c maxint.c  makefile.in \
  13483. -     README configure configure.in machine.h.in copyright \
  13484. -     tutorial.c tutadv.c rk4.dat ls.dat makefile $(FLIST)
  13485. -
  13486. -
  13487. -# Different configurations
  13488. -all:  part1 part2 part3 zpart1 zpart2 
  13489. -basic: part1 part2
  13490. -sparse: part1 part2 part3 
  13491. -complex: part1 part2 zpart1 zpart2
  13492. -
  13493. -
  13494. -$(LIST1): $(HBASE)
  13495. -part1: $(LIST1)
  13496. -    ar ru meschach.a $(LIST1); $(RANLIB) meschach.a
  13497. -
  13498. -$(LIST2): $(HBASE) matrix2.h
  13499. -part2: $(LIST2)
  13500. -    ar ru meschach.a $(LIST2); $(RANLIB) meschach.a
  13501. -
  13502. -$(LIST3): $(HBASE) sparse.h sparse2.h
  13503. -part3: $(LIST3)
  13504. -    ar ru meschach.a $(LIST3); $(RANLIB) meschach.a
  13505. -
  13506. -$(ZLIST1): $(HBASDE) zmatrix.h
  13507. -zpart1: $(ZLIST1)
  13508. -    ar ru meschach.a $(ZLIST1); ranlib meschach.a
  13509. -
  13510. -$(ZLIST2): $(HBASE) zmatrix.h zmatrix2.h 
  13511. -zpart2: $(ZLIST2)
  13512. -    ar ru meschach.a $(ZLIST2); ranlib meschach.a
  13513. -
  13514. -$(OLDLIST): $(HBASE) sparse.h sparse2.h 
  13515. -oldpart: $(OLDLIST)
  13516. -    ar ru meschach.a $(OLDLIST); ranlib meschach.a
  13517. -
  13518. -
  13519. -
  13520. -#######################################
  13521. -
  13522. -tar:
  13523. -    - /bin/rm -f $(MES_PAK).tar
  13524. -    chmod 644 `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  13525. -    $(OTHERS) $(HLIST)  `echo $(TORTURE) | sed -e 's/\.o/.c/g'` 
  13526. -    chmod 755 configure
  13527. -    $(MAKE) list
  13528. -    $(TAR) cvf $(MES_PAK).tar \
  13529. -     `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  13530. -    $(HLIST)  $(OTHERS) \
  13531. -    `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  13532. -    MACHINES DOC
  13533. -
  13534. -# use this only for PC machines    
  13535. -msdos-zip:
  13536. -    - /bin/rm -f $(MES_PAK).zip
  13537. -    chmod 644 `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  13538. -    $(OTHERS) $(HLIST) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` 
  13539. -    chmod 755 configure
  13540. -    $(MAKE) list
  13541. -    $(ZIP)  $(MES_PAK).zip \
  13542. -     `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  13543. -    $(HLIST)  $(OTHERS) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  13544. -    MACHINES DOC
  13545. -    
  13546. -
  13547. -fullshar:
  13548. -    - /bin/rm -f $(MES_PAK).shar;
  13549. -    chmod 644 `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  13550. -    $(OTHERS) $(HLIST) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` 
  13551. -    chmod 755 configure
  13552. -    $(MAKE) list
  13553. -    $(SHAR) `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  13554. -    $(HLIST)  $(OTHERS) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  13555. -    MACHINES DOC > $(MES_PAK).shar
  13556. -
  13557. -shar:
  13558. -    - /bin/rm -f meschach1.shar meschach2.shar meschach3.shar \
  13559. -    meschach4.shar oldmeschach.shar meschach0.shar 
  13560. -    chmod 644 `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  13561. -    $(OTHERS) $(HLIST) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` 
  13562. -    chmod 755 configure    
  13563. -    $(MAKE) list
  13564. -    $(SHAR) `echo $(LIST1) | sed -e 's/\.o/.c/g'` > meschach1.shar
  13565. -    $(SHAR) `echo $(LIST2) | sed -e 's/\.o/.c/g'` > meschach2.shar
  13566. -    $(SHAR) `echo $(LIST3) | sed -e 's/\.o/.c/g'` > meschach3.shar    
  13567. -    $(SHAR) `echo $(ZLIST1) | sed -e 's/\.o/.c/g'` \
  13568. -      `echo $(ZLIST2) | sed -e 's/\.o/.c/g'` > meschach4.shar
  13569. -    $(SHAR) `echo $(OLDLIST) | sed -e 's/\.o/.c/g'` > oldmeschach.shar
  13570. -    $(SHAR) $(OTHERS) `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  13571. -      $(HLIST)  DOC MACHINES  > meschach0.shar
  13572. -
  13573. -list:
  13574. -    /bin/rm -f $(FLIST)
  13575. -    ls -lR `echo $(ALL_LISTS) | sed -e 's/\.o/.c/g'` \
  13576. -    `echo $(TORTURE) | sed -e 's/\.o/.c/g'` \
  13577. -    $(HLIST) $(OTHERS) MACHINES DOC \
  13578. -    |awk '/^$$/ {print};/^[-d]/ {printf("%s %s   %10d %s %s %s %s\n", \
  13579. -     $$1,$$2,$$5,$$6,$$7,$$8,$$9)}; /^[^-d]/ {print}' \
  13580. -    > $(FLIST)
  13581. -
  13582. -
  13583. -
  13584. -clean:
  13585. -    /bin/rm -f *.o core asx5213a.mat iotort.dat 
  13586. -
  13587. -cleanup:
  13588. -    /bin/rm -f *.o core asx5213a.mat iotort.dat *.a 
  13589. -
  13590. -alltorture: torture sptort ztorture memtort itertort mfuntort iotort
  13591. -
  13592. -torture:torture.o meschach.a
  13593. -    $(CC) $(CFLAGS) $(DEFS) -o torture torture.o \
  13594. -    meschach.a $(LIBS)
  13595. -sptort:sptort.o meschach.a
  13596. -    $(CC) $(CFLAGS) $(DEFS) -o sptort sptort.o \
  13597. -    meschach.a $(LIBS)
  13598. -memtort: memtort.o meschach.a
  13599. -    $(CC) $(CFLAGS) $(DEFS) -o memtort memtort.o \
  13600. -    meschach.a $(LIBS)
  13601. -ztorture:ztorture.o meschach.a
  13602. -    $(CC) $(CFLAGS) $(DEFS) -o ztorture ztorture.o \
  13603. -    meschach.a $(LIBS)
  13604. -itertort: itertort.o meschach.a
  13605. -    $(CC) $(CFLAGS) $(DEFS) -o itertort itertort.o \
  13606. -    meschach.a $(LIBS)
  13607. -
  13608. -iotort: iotort.o meschach.a
  13609. -    $(CC) $(CFLAGS) $(DEFS) -o iotort iotort.o \
  13610. -    meschach.a $(LIBS)
  13611. -mfuntort: mfuntort.o meschach.a
  13612. -    $(CC) $(CFLAGS) $(DEFS) -o mfuntort mfuntort.o \
  13613. -    meschach.a $(LIBS)
  13614. -tstmove: tstmove.o meschach.a
  13615. -    $(CC) $(CFLAGS) $(DEFS) -o tstmove tstmove.o \
  13616. -    meschach.a $(LIBS)
  13617. -tstpxvec: tstpxvec.o meschach.a
  13618. -    $(CC) $(CFLAGS) $(DEFS) -o tstpxvec tstpxvec.o \
  13619. -    meschach.a $(LIBS)
  13620. -
  13621. //GO.SYSIN DD MACHINES/Linux/makefile
  13622. echo MACHINES/Linux/machine.h 1>&2
  13623. sed >MACHINES/Linux/machine.h <<'//GO.SYSIN DD MACHINES/Linux/machine.h' 's/^-//'
  13624. -/* machine.h.  Generated automatically by configure.  */
  13625. -/* Any machine specific stuff goes here */
  13626. -/* Add details necessary for your own installation here! */
  13627. -
  13628. -/* This is for use with "configure" -- if you are not using configure
  13629. -    then use machine.van for the "vanilla" version of machine.h */
  13630. -
  13631. -/* Note special macros: ANSI_C (ANSI C syntax)
  13632. -            SEGMENTED (segmented memory machine e.g. MS-DOS)
  13633. -            MALLOCDECL (declared if malloc() etc have
  13634. -                    been declared) */
  13635. -
  13636. -/* #undef const */
  13637. -
  13638. -/* #undef MALLOCDECL */
  13639. -#define NOT_SEGMENTED 1
  13640. -/* #undef HAVE_COMPLEX_H */
  13641. -#define HAVE_MALLOC_H 1
  13642. -#define STDC_HEADERS 1
  13643. -#define HAVE_BCOPY 1
  13644. -#define HAVE_BZERO 1
  13645. -#define CHAR0ISDBL0 1
  13646. -/* #undef WORDS_BIGENDIAN */
  13647. -#define U_INT_DEF 1
  13648. -#define VARARGS 1
  13649. -
  13650. -
  13651. -/* for basic or larger versions */
  13652. -#define COMPLEX 1
  13653. -#define SPARSE 1
  13654. -
  13655. -/* for loop unrolling */
  13656. -/* #undef VUNROLL */
  13657. -/* #undef MUNROLL */
  13658. -
  13659. -/* for segmented memory */
  13660. -#ifndef NOT_SEGMENTED
  13661. -#define    SEGMENTED
  13662. -#endif
  13663. -
  13664. -/* if the system has malloc.h */
  13665. -#ifdef HAVE_MALLOC_H
  13666. -#define    MALLOCDECL    1
  13667. -#include    <malloc.h>
  13668. -#endif
  13669. -
  13670. -/* any compiler should have this header */
  13671. -/* if not, change it */
  13672. -#include        <stdio.h>
  13673. -
  13674. -
  13675. -/* Check for ANSI C memmove and memset */
  13676. -#ifdef STDC_HEADERS
  13677. -
  13678. -/* standard copy & zero functions */
  13679. -#define    MEM_COPY(from,to,size)    memmove((to),(from),(size))
  13680. -#define    MEM_ZERO(where,size)    memset((where),'\0',(size))
  13681. -
  13682. -#ifndef ANSI_C
  13683. -#define ANSI_C 1
  13684. -#endif
  13685. -
  13686. -#endif
  13687. -
  13688. -/* standard headers */
  13689. -#ifdef ANSI_C
  13690. -#include    <stdlib.h>
  13691. -#include    <stddef.h>
  13692. -#include    <string.h>
  13693. -#include    <float.h>
  13694. -#endif
  13695. -
  13696. -
  13697. -/* if have bcopy & bzero and no alternatives yet known, use them */
  13698. -#ifdef HAVE_BCOPY
  13699. -#ifndef MEM_COPY
  13700. -/* nonstandard copy function */
  13701. -#define    MEM_COPY(from,to,size)    bcopy((char *)(from),(char *)(to),(int)(size))
  13702. -#endif
  13703. -#endif
  13704. -
  13705. -#ifdef HAVE_BZERO
  13706. -#ifndef MEM_ZERO
  13707. -/* nonstandard zero function */
  13708. -#define    MEM_ZERO(where,size)    bzero((char *)(where),(int)(size))
  13709. -#endif
  13710. -#endif
  13711. -
  13712. -/* if the system has complex.h */
  13713. -#ifdef HAVE_COMPLEX_H
  13714. -#include    <complex.h>
  13715. -#endif
  13716. -
  13717. -/* If prototypes are available & ANSI_C not yet defined, then define it,
  13718. -    but don't include any header files as the proper ANSI C headers
  13719. -        aren't here */
  13720. -#define HAVE_PROTOTYPES 1
  13721. -#ifdef HAVE_PROTOTYPES
  13722. -#ifndef ANSI_C
  13723. -#define ANSI_C  1
  13724. -#endif
  13725. -#endif
  13726. -
  13727. -/* floating point precision */
  13728. -
  13729. -/* you can choose single, double or long double (if available) precision */
  13730. -
  13731. -#define FLOAT         1
  13732. -#define DOUBLE         2
  13733. -#define LONG_DOUBLE     3
  13734. -
  13735. -/* #undef REAL_FLT */
  13736. -/* #undef REAL_DBL */
  13737. -
  13738. -/* if nothing is defined, choose double precision */
  13739. -#ifndef REAL_DBL
  13740. -#ifndef REAL_FLT
  13741. -#define REAL_DBL 1
  13742. -#endif
  13743. -#endif
  13744. -
  13745. -/* single precision */
  13746. -#ifdef REAL_FLT
  13747. -#define  Real float
  13748. -#define  LongReal float
  13749. -#define REAL FLOAT
  13750. -#define LONGREAL FLOAT
  13751. -#endif
  13752. -
  13753. -/* double precision */
  13754. -#ifdef REAL_DBL
  13755. -#define Real double
  13756. -#define LongReal double
  13757. -#define REAL DOUBLE
  13758. -#define LONGREAL DOUBLE
  13759. -#endif
  13760. -
  13761. -
  13762. -/* machine epsilon or unit roundoff error */
  13763. -/* This is correct on most IEEE Real precision systems */
  13764. -#ifdef DBL_EPSILON
  13765. -#if REAL == DOUBLE
  13766. -#define    MACHEPS    DBL_EPSILON
  13767. -#elif REAL == FLOAT
  13768. -#define    MACHEPS    FLT_EPSILON
  13769. -#elif REAL == LONGDOUBLE
  13770. -#define MACHEPS LDBL_EPSILON
  13771. -#endif
  13772. -#endif
  13773. -
  13774. -#define F_MACHEPS 1.19209e-07
  13775. -#define D_MACHEPS 2.22045e-16
  13776. -
  13777. -#ifndef MACHEPS
  13778. -#if REAL == DOUBLE
  13779. -#define    MACHEPS    D_MACHEPS
  13780. -#elif REAL == FLOAT  
  13781. -#define MACHEPS F_MACHEPS
  13782. -#elif REAL == LONGDOUBLE
  13783. -#define MACHEPS D_MACHEPS
  13784. -#endif
  13785. -#endif
  13786. -
  13787. -/* #undef M_MACHEPS */
  13788. -
  13789. -/********************
  13790. -#ifdef DBL_EPSILON
  13791. -#define    MACHEPS    DBL_EPSILON
  13792. -#endif
  13793. -#ifdef M_MACHEPS
  13794. -#ifndef MACHEPS
  13795. -#define MACHEPS    M_MACHEPS
  13796. -#endif
  13797. -#endif
  13798. -********************/
  13799. -
  13800. -#define    M_MAX_INT 2147483647
  13801. -#ifdef    M_MAX_INT
  13802. -#ifndef MAX_RAND
  13803. -#define    MAX_RAND ((double)(M_MAX_INT))
  13804. -#endif
  13805. -#endif
  13806. -
  13807. -/* for non-ANSI systems */
  13808. -#ifndef HUGE_VAL
  13809. -#define HUGE_VAL HUGE
  13810. -#endif
  13811. -
  13812. -
  13813. -#ifdef ANSI_C
  13814. -extern    int    isatty(int);
  13815. -#endif
  13816. -
  13817. //GO.SYSIN DD MACHINES/Linux/machine.h
  13818.